2

I am trying to use SDL2_mixer for sound but I get these errors

undefined reference to `Mix_OpenAudio'

undefined reference to `Mix_LoadWAV_RW'

undefined reference to `Mix_PlayChannelTimed'

According to Lazy Foo's tutorials undefined references mean that I have something wrong in my linker settings how every I believe I have it right. It goes as follows:

-lmingw32 -lSDL2main -lSDL2 -lSDL2_mixer -lSOIL -lOpenGL32

Additionally the search directories for the header and lib files are correct (I have triple checked) and the .dll is in the same directory as the executable. The code files also have the corresponding #include directories. There are not any more things I can think to try so any help is appreciated

0ctoDragon
  • 531
  • 5
  • 18

2 Answers2

3

I was trying to compile a 64-bit Mixer with the 32-bit SDL.

chrylis -cautiouslyoptimistic-
  • 67,584
  • 19
  • 106
  • 140
0ctoDragon
  • 531
  • 5
  • 18
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Wahyu Kristianto Jun 03 '14 at 03:25
  • 1
    @WahyuKristianto This is in fact a poorly-phrased but accurate answer by the OP: The problem was that he was trying to link 32-bit and 64-bit binaries together. – chrylis -cautiouslyoptimistic- Jun 03 '14 at 03:41
2

I think you've the SDL mixer runtime binaries alone extracted into a directory. However, for compiling and linking you need the development libraries which has the stub library libSDL2_mixer.dll.a file necessary for linking.

In the SDL_mixer page, you've two sections: Runtime Binaries and Development Libraries. In the second section, download SDL2_mixer-devel-2.0.0-mingw.tar.gz (MinGW 32/64-bit). Extract it to a directory and add the (/lib) directory path to C::B and pass -lSDL2_mixer and it should link just fine.

When you run the executable, make sure SDL2_mixer.dll (from the \bin directory of the download) is present in the same directory for runtime dynamic linking to work.

legends2k
  • 27,643
  • 22
  • 108
  • 196
  • I had originally downloaded and extracted SDL2_mixer-devel-2.0.0-mingw.tar.gz and libSDL2_mixer.dll.a is in the same directory as C::B is linked too under build options->search drectories->linker – 0ctoDragon Jun 02 '14 at 22:58
  • What is the error you get? Also try to pass `-lSDL2_mixer` before other SDL linker options; [the order matters](http://stackoverflow.com/questions/11893996/why-does-the-order-of-l-option-in-gcc-matter). – legends2k Jun 02 '14 at 22:59
  • I tried moving -lSDL2_mixer around like you said and the didn't help. – 0ctoDragon Jun 02 '14 at 23:07
  • ||=== Build: Debug in 0ctoEngine_1.0 (compiler: GNU GCC Compiler) ===| obj\Debug\game_state.o||In function `ZN9GameState5logicEv':| C:\WorkSpace\Code\show\0ctoEngine_1.0\game_state.cpp|91|undefined reference to `Mix_PlayChannelTimed'| obj\Debug\start_up.o||In function `Z4initv':| C:\WorkSpace\Code\show\0ctoEngine_1.0\start_up.cpp|6|undefined reference to `Mix_OpenAudio'| obj\Debug\start_up.o||In function `Z10load_filesv':| C:\WorkSpace\Code\show\0ctoEngine_1.0\start_up.cpp|33|undefined reference to `Mix_LoadWAV_RW'| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===| – 0ctoDragon Jun 02 '14 at 23:08
  • That is the build massages log – 0ctoDragon Jun 02 '14 at 23:08
  • Check if the path is correct. I know it's frusturating that you've already told you've triple checked but sometimes '/' and '\' matters in Windows. I always prefer '/' for both Linux and Windows and it works. – legends2k Jun 02 '14 at 23:11
  • it seems like C::B changes it back to '\' by default. Either way it made no difference. Thanks for your help BTW – 0ctoDragon Jun 02 '14 at 23:17