View Full Version : error too long to list in subject line

03-13-2012, 01:26 AM
I'm new to OpenGL. I tried compiling the first program in the red book (the white square against a black background) and was successful. Now I'm trying to build the classic Asteroids game. My compilation command is as follows:

g++ -o asteroids -I/usr/include Asteroid.cpp bullet.cpp Projectile.cpp ship.cpp -lglut -lGLU -lGL

But this spits out the following error. I have no idea what it is:

/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

help please,

03-13-2012, 03:47 AM
You have to compile each *.cpp file individually and then link them together. Just calling g++ once will only work if you compile only one file. Try:

g++ -I/usr/include -c Asteroid.cpp
g++ -I/usr/include -c bullet.cpp
g++ -I/usr/include -c Projectile.cpp
g++ -I/usr/include -c ship.cpp

g++ *.o -lglut -lGLU -lGL -o asteroids

03-13-2012, 04:09 AM
The simple answer to this not so obscure error is that there isn't a main function anywhere in the source code - thus there is no entry point for the application and therefore linkage fails.

BTW, this is nothing specific to Linux, Windows, Unix, OSX or OpenGL. It's C/C++ beginners mistake.

03-14-2012, 08:27 AM
Actually compiling the .cpp files individually gives me the same error. And yes, I DO have a main() function. What I found out fixed the issue is in the appendix of the blue book:

g++ -I/usr/include -o asteroids Asteroid.cpp bullet.cpp Projectile.cpp main.cpp ship.cpp -lX11 -lXi -lglut -lGL -lGLU -lm

now I don't know what the libraries X11, Xi, and m do but it works with them. There's another library the book says to link to. It's called Xmu but my system can't find it and it works without it.

03-14-2012, 08:38 AM
You didn't include main.cpp in your first post.

X11 is a protocol libX11 is the interface library for your implementation of the X Window System. libXi is the X Input Library libm is the C math library. I doubt that linking against these libs solved your problem.