Author Topic: SDL_OpenGL and undefined references.  (Read 7780 times)

Offline SplinterOfChaos

  • Single posting newcomer
  • *
  • Posts: 8
SDL_OpenGL and undefined references.
« on: May 10, 2008, 09:41:27 pm »
I've been using SDL for a while with no problems, but I want to use OpenGL now (through SDL).
So when I say #include "SDL/SDL_opengl.h", I expect it to be included. But then, why do I get all these errors?

Quote
obj\Debug\main.o||In function `Z7init_GLv':|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|141|undefined reference to `glClearColor@16'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|143|undefined reference to `glMatrixMode@4'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|144|undefined reference to `glLoadIdentity@0'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|145|undefined reference to `glOrtho@48'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|147|undefined reference to `glMatrixMode@4'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|148|undefined reference to `glLoadIdentity@0'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|150|undefined reference to `glGetError@0'|
C:\Documents and Settings\Owner\Desktop\Programming\C++\WorkSpace\OpenGL Graphics\SDL_Work.h|152|undefined reference to `glGetError@0'|
||=== Build finished: 8 errors, 0 warnings ===|

I tried, to no avail,

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glext.h>

but that didn't really do anything. Some things are defined (like GL_STACK_OVERFLOW and other GLenums), but these won't be defined. I don't know what .lib files extra I'm supposed to be including. I though I might see them in MinGW/include/GL, but that had only .h files, as I should have guessed.

So, what do I do? I searched and found a ton of threads on this, but none really helped me.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: SDL_OpenGL and undefined references.
« Reply #1 on: May 11, 2008, 09:06:57 am »
So, what do I do? I searched and found a ton of threads on this, but none really helped me.
You are missing to link against opengl32 at least. I suggest you either:
- use the wizard to create an opengl app for you and "copy" the project settings
...or:
- use the wizard to create a SDL app for you and "copy" the project settings (I never did that)
Notice that the order of how you link library matters. So the once that are "core" libs like opengl (where SDL is based on) must come first.

BTW: There is not only our forum to search for. Google gave me the right hints when googleing for "undefined reference to `glClearColor@16'".
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline zygimantus

  • Single posting newcomer
  • *
  • Posts: 3
Re: SDL_OpenGL and undefined references.
« Reply #2 on: October 16, 2016, 08:31:32 pm »
You should add to your *.cbp file this:

Code: xml
<Linker>
       <Add library="GL" />
</Linker>

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: SDL_OpenGL and undefined references.
« Reply #3 on: October 17, 2016, 07:37:40 pm »
nice grave digger ;)

You should add to your *.cbp file this:
NO NEVER EDIT THE .CBP FILE DIRECTLY*)

if you have to add a library do it with
Project->Build options->Linker settings->Link libraries->Add->GL

*) why not? Well you can do it, but at your own risk and if a noob is reading this he adds your lines somewhere (because in your answer is missing the whole target context) and then he comes here and wants help....