1

I want to write a simple SDL OpenGL app, Codeblocks is the IDE I use. When I create a new OpenGL project, it compiles fine, but if I try to use a function from the SDL header, le wild "undefined reference error" occurs. The same goes for the other direction, if I create a new SDL project, I can use the SDL functions without problems but I get a "undefined reference error" for the OpenGL functions...

NOTES:

  • I Use Ubuntu 11.10
  • I have installed the SDL and the OpenGL packages
genpfault
  • 51,148
  • 11
  • 85
  • 139
Moritz Schöfl
  • 763
  • 2
  • 7
  • 19
  • I don't know codeblocks. That said, if it has a place to add linker and/or compiler flags, copy all the `-l, -L, and -I` flags from one project to another. Somewhere in the OpenGL project settings you'll likely find something like this "-lglut -lGL -lGLU". The `-l` flag indicates what libraries to link against. The `-L` adds directories to the search path for those libraries. `-I` adds directories to where the compiler searches for included headers, but it sounds like that's not your problem. – Brian McFarland Feb 22 '12 at 21:15

2 Answers2

2

You need to add the correct library. Headers just give the compiler sort of a index. But you need to tell the linker which libraries to actually pull in. You should find the linker options at the build settings. You need the following libraries for SDL + OpenGL

  • libGL.so ( -lGL linker switch )
  • libSDL.so ( -lSDL linker switch)

You may also require libGLU.so if you're using glu… functions.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
2

Asking pkg-config is the preferable thing for obtain the particular flags and options needed for compilation and linkage against SDL and Mesa's GL+GLU. (Some GL implemenetations may not be shipping .pc files, but they should still be used where available.)

jørgensen
  • 10,149
  • 2
  • 20
  • 27