"Beginning OpenGL Game Programming II" 1st sdl code error

Started by
5 comments, last by Setlec 14 years, 7 months ago
Hello, i've downloaded the latest bugfix of the sample code for "Beginning OpenGL Game Programming II" and when i try to compile the ch 1 "simple" with code::block under linux i get those SDL errors:
Quote: -------------- Build: Debug in simple --------------- Linking console executable: ../simple_debug obj/Debug/src/main.o: In function `main': ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:109: undefined reference to `SDL_Init' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:115: undefined reference to `SDL_GL_SetAttribute' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:116: undefined reference to `SDL_GL_SetAttribute' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:117: undefined reference to `SDL_GL_SetAttribute' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:118: undefined reference to `SDL_GL_SetAttribute' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:119: undefined reference to `SDL_GL_SetAttribute' obj/Debug/src/main.o:~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:120: more undefined references to `SDL_GL_SetAttribute' follow obj/Debug/src/main.o: In function `main': ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:123: undefined reference to `SDL_WM_SetCaption' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:126: undefined reference to `SDL_SetVideoMode' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:134: undefined reference to `SDL_Quit' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:144: undefined reference to `SDL_PollEvent' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:165: undefined reference to `SDL_GL_SwapBuffers' ~/Source Code/OpenGL 3.0/chapter_1/simple/src/main.cpp:168: undefined reference to `SDL_Quit' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 0 seconds) 13 errors, 0 warnings
any thoughts? oh i'm a noob at programming!
Advertisement
Looks like you've forgotten to link your program with the SDL library.

Not sure how you do it in Code::Blocks, but using vanilla gcc it would usually just be a matter of adding the argument -lSDL to the compiler.
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
when you say link the sdl library you mean adding the sdl headers?
No. SDL, and other libraries as well, ships with two parts: header files and library files.

Header files contains function declarations which is only used to tell the compiler what function are available for use. Any time you #include a header file, you're basicly telling the compiler "You may not know exactly what these functions are, but it's ok to use them because I'll provide them later."

Library files on the other hand contains the actual fragments of executable machine code for those functions.

Once it's time for the compiler to link all your bits and pieces of code into the final executable, you need to tell the compiler where it should look for the code for the functions that you haven't already supplied. This is where the arguments to the linker come into play. The -lSDL argument I mentioned before tells gcc: "If I've tried to use a function that you can't find, you should also try looking for it in the file called libSDL.so".

So, you need to find a way to specify in code::blocks in which files it should look for functions that you don't supply yourself. A bit of googling turned up this thread, which should point you in the right direction.
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
wow that actually helped me a lot thank you very much! I'll post as soon as i get the the compiled code!

Cheers

ok i've succes fully compiled the Code thanks to you Luctus!
Hi Setlec,

I'll take a look at this, you aren't the first person to report this linking problem with the first example. I'm away for the next week, but I'll fix up a new version asap. Glad you got it working OK in the end.

Luke.
Member of the NeHe team.
Hello Kazade,

I would like to thank you for your great book. I started OpenGL programing thank to your book.

Cheers

This topic is closed to new replies.

Advertisement