Sample program build problem

Hey im running ubuntu and am trying to compile and run a sample opengl program. It compiles fine, but when I try to build it all these errors come up saying the same thing.

undefined reference to glBegin, glClear, glutInit, etc.

Is there something special I need to do? I know its something simple but ive never done this sort of thing before.

I guess you want to know how to link libs after compiling source codes.

You need to include link option for OpenGL libraries:
-lGL -lGLU -lglut

For example, if you have only one source file, let’s say “test.cpp”;
g++ -o test test.cpp -lGL -lGLU -lglut

If you have more than one source files, the thing becomes more complicated. So you better have Makefile for big project.

Let’s say you have 3 source files and you compiled them already;

g++ code1.o code2.o code3.o -o output -lGL -lGLU -lglut

Thank you Songho! I knew it would be something simple like that. You saved me from having a huge headache.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.