Wednesday, August 29, 2018

c - Undefined reference to SDL functions using Code::Blocks



There are quite a few similar topics on SO regarding this but I have exhausted all the suggestions on 15 similar threads.



Upon running tutorial code utilizing the SDL library, the IDE is complaining of "undefined reference" to all functions pertaining to SDL.



Situation




Architecture: 64 bit



IDE: CodeBlocks 16.01



Compiler: GNU GCC



What I have tried to do



1) I told the compiler to find header under directory:

.....\i686-w64-mingw32\include\SDL2 using relative paths



I did NOT select \include NOR did I select .....\x86_64-w64-mingw32\include\SDL2



2) I told compiler to find library files under directory:
.....\i686-w64-mingw32\lib using relative paths



I did NOT select ....\lib NOR did I select .....\x86_64-w64-mingw32\lib



3) When linking the libraries, I included four libraries under the directory

....\i686-w64-mingw32\lib and NOT the other directories as mentioned above.



4) The order in which the libraries were linked are as follows:



SDL2main.lib



SDL2.lib



SDL2test.lib




5) I ensured that the properties of main.c were such that compile file was checked, link file was checked, and the belongs in targets debug and release were both checked.



Build log:




-------------- Build: Debug in Snake Game (compiler: GNU GCC Compiler)---------------



mingw32-g++.exe
-L......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib
-o "bin\Debug\Snake Game.exe" obj\Debug\main.o -lmingw32 ......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib\libSDL2main.a

......\Downloads\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib\libSDL2.a
obj\Debug\main.o: In function SDL_main':
C:/XXX/XXX/XXX/XXX/XXX/main.c:9: undefined
reference to
SDL_WM_SetCaption'




The log goes on and on with undefined references.



Can anybody guide me in solving this linking problem?


Answer




There is no SDL_WM_SetCaption in SDL2. Your code is likely to be using older SDL 1.2. Either use correct library or modify your code e.g following https://wiki.libsdl.org/MigrationGuide


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...