Сool
DaMarkov wrote: ↑2019-03-07, 01:59
Here is a better example of the bug:
https://zedonline.sourceforge.io/jv_decoder_bug2.cpp
If I compile this file against SDL_mixer.lib everything works. If I link to SDL2_mixer.lib sound is corrupted.
Do you also link to SDL2_mixer.lib after switching from SDL1 to SDL2?
Ok.
This
#pragma comment preprocessor directive is for Visual Studio only.
This is not part of The C++ language. Connecting libraries is done for you (SDL, SDL2) through the Property Pages dialog box.
In my case for
QtCreator, I have to set the path to the /lib folder and the /include folder - where the header files and binary implementation files are located. This is only if the library was not installed on OS (in my case on Ubuntu). Then I have to specify which libraries from the /lib folder I'm going to use.
It looks complicated. However, in fact, everything is simple.
A text file is automatically created for each project
".pro". To specify paths (if the library has special paths) in this file, write:
LIBS += -L"/../path_to_folder/lib"
INCLUDEPATH += "/../path_to_foder/include"
Then connect what we need:
LIBS += \
-lSDL2 \
-lSDL2_image \
-lSDL2_mixer \
Instead of the character 'l' in the beginning when you compile is automatically populated with "lib" - that is, here are the connection libSDL2, libSDL2_image, libSDL2_mixer.
Respectively for SDL (1.2..) that would be:
LIBS += \
-lSDL \
-lSDL_image \
-lSDL_mixer \
The project will be built with the libraries that were installed in the operating system and specified in the text file PRO. An error can occur if your library has the same name as another library in OS.
However, this is not the case with SDL (libSDL != libSDL2).
In the code, it is enough to specify the connection of the header of the used library.
For example #include <SDL2/SDL.h>.
What happens if we forget to include the necessary library in the PRO file (for example libSDL2_mixer)? When building the project, we get a compilation error like:
--------------------------------------------------------------------------------------------------------
g++ -o bin/sdl2_bag_sound objs/main.o objs/audio_proc.o objs/bitstream.o objs/jv_format.o objs/video_proc.o -lSDL2 -lSDL2_image
objs/main.o: In function `main':
/home/.../SDL/Testing_SDL2/Sound/sdl2_bag_sound/main.cpp:73: undefined reference to `Mix_OpenAudio'
/home/.../SDL/Testing_SDL2/Sound/sdl2_bag_sound/main.cpp:78: undefined reference to `Mix_Volume'
Makefile:255: recipe for target 'bin/sdl2_bag_sound' failed
/home/.../SDL/Testing_SDL2/Sound/sdl2_bag_sound/main.cpp:94: undefined reference to `Mix_QuickLoad_WAV'
/home/.../SDL/Testing_SDL2/Sound/sdl2_bag_sound/main.cpp:103: undefined reference to `Mix_PlayChannelTimed'
collect2: error: ld returned 1 exit status
make: *** [bin/sdl2_bag_sound] Error 1
--------------------------------------------------------------------------------------------------------
The possibility of using SDL libraries instead of SDL2 is excluded.
(I have a cold and can spend more time on Z)
