Undefined reference to 'SDL_"lots of different stuff"

Started by
3 comments, last by rip-off 13 years, 1 month ago
I just started on the book "Beginning OpenGL Game Programming" but I', having problems with the chapter 1 code.

I use Code::Blocks and when i try to compile the source for the first example program these errors pop up in the "Build messages" section:


obj\Debug\main.o||In function `SDL_main':|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|106|undefined reference to `SDL_Init'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|112|undefined reference to `SDL_GL_SetAttribute'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|113|undefined reference to `SDL_GL_SetAttribute'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|114|undefined reference to `SDL_GL_SetAttribute'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|115|undefined reference to `SDL_GL_SetAttribute'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|116|undefined reference to `SDL_GL_SetAttribute'|
obj\Debug\main.o:G:\Programmering\Game Programming OpenGL\simple\main.cpp|117|more undefined references to `SDL_GL_SetAttribute' follow|
obj\Debug\main.o||In function `SDL_main':|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|120|undefined reference to `SDL_WM_SetCaption'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|123|undefined reference to `SDL_SetVideoMode'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|131|undefined reference to `SDL_Quit'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|141|undefined reference to `SDL_PollEvent'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|162|undefined reference to `SDL_GL_SwapBuffers'|
G:\Programmering\Game Programming OpenGL\simple\main.cpp|165|undefined reference to `SDL_Quit'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'|
||=== Build finished: 14 errors, 0 warnings ===|

I've spent some time trying to figure this out.

I'm really exited about starting OpenGL, so some help would be awesome :D


-IsNe
"The trouble with quotes on the internett is that you can never know if they are genuine"
--------------- Abraham Lincoln (1809-1865)
Advertisement
You aren't linking to the SDL libraries correctly. I don't remember how to do this on CodeBlocks, but if you go to the compiler options there should be a tab about linking options. Add the following lines:

-lSDL -lSDLmain.

Make sure that the $YOUR_SDL_FOLDER/lib path is in the library search path. This can also be set in the compiler options dialog.
Thanks, that got rid of some, now i got this:


||Warning: .drectve `/manifestdependency:"type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b'" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0x5)||undefined reference to `__security_cookie'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0x65)||undefined reference to `_alloca_probe_16'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0x80)||undefined reference to `@__security_check_cookie@4'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0x8c)||undefined reference to `SDL_strlcpy'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0xa2)||undefined reference to `SDL_GetError'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0xbe)||undefined reference to `@__security_check_cookie@4'|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\SDLmain.lib(.\release_nostdio\SDL_win32_main.obj):(.text[_main]+0xe7)||undefined reference to `SDL_SetModuleHandle'|
16]+0x5)||undefined reference to `__security_cookie'|
16]+0x43)||undefined reference to `_alloca_probe_16'|
16]+0x58)||undefined reference to `SDL_strlcpy'|
16]+0x72)||undefined reference to `_alloca_probe_16'|
16]+0x9b)||undefined reference to `@__security_check_cookie@4'|
||=== Build finished: 12 errors, 1 warnings ===|
"The trouble with quotes on the internett is that you can never know if they are genuine"
--------------- Abraham Lincoln (1809-1865)
Found the problem, but now i got this:


c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'|
||=== Build finished: 1 errors, 0 warnings ===|

googled it, but really can't find any solution that helps.
I am using Code::Blocks btw, and i can post source-code if that would be of help
"The trouble with quotes on the internett is that you can never know if they are genuine"
--------------- Abraham Lincoln (1809-1865)
SDL provides SDLmain.lib which provides OS specific main implementations, such as WinMain(). The main() you write is actually #defined as SDL_main(). You need to link -lSDLmain aswell.

This topic is closed to new replies.

Advertisement