I'm trying to write a simple game using SDL and OpenGL. Up until now, I was using purely SDL and pixel manipulations on the framebuffer to draw lines and other shapes. However, as you would expect, that got unbearably slow as the number of objects on the screen increased.
Now I tried to switch to OpenGL. The includes work fine, SDL_GL_SetAttribute works fine, and SDL_SetVideoMode works fine so long as I don't use any purely OpenGL functions. However as soon as I try to use an opengl function (that I copied from a tutorial), my compiler gives me an Undefined Reference error for all the pure OpenGL functions.

/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:47: undefined reference to `glViewport'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:48: undefined reference to `glClearColor'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:49: undefined reference to `glClearDepth'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:50: undefined reference to `glDepthFunc'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:51: undefined reference to `glEnable'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:52: undefined reference to `glShadeModel'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:53: undefined reference to `glMatrixMode'
/home/usrname/NetBeansProjects/SDLPROJ/main.cpp:54: undefined reference to `glMatrixMode'

As you can see, I'm using NetBeans and Ubuntu 9.04. Are there special linker options that I need to add for my program to be dynamically linked to the OpenGL dlls? Any help would be appreciated!

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

Thanks for the help! In addition to what you said, I had to add /usr/lib/libGL.so to the list of libraries in the linker options. For all the tutorials there are for openGL, you'd think things like these would be easy to find.
Once again, thanks for the help! Problem Solved!

Ah excellent. Yes I should've noticed from your output that you were using an IDE and not just compiling on the command line or makefile.
Good to know it's working.

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

________________________________
I really have almost same problem can you clarify it.
my library exits under /usr/lib/GL, but the code genaretes error about all gl functions like ---> udefined reference to 'glMatrixMode'

any answer or link will be apriciated.

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

You need to link to the GL library. What you need is to add the -lGL in your linker options. Likewise if you need glut or glu library functions you want -lglut -lglu respectively.
The trick is to remember that if you use any functions from included header files that come from other sources you need to link to the library containing the function definition. This excludes the C++ standard library as this is done automatically by your compiler.

EDIT: and ensure these libraries exist, likely in /usr/lib

On my Kubuntu:

gcc ogl_app.c -lGL -lGLU -lGLEW -lglut

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.