I wrote a program on Ubuntu 11.04 that uses freeglut. It worked fine. Then I got another computer and tried to run the program on a fresh install of Ubuntu 11.04. Doesn\'t w
The order in which you specify the objects you want to link to (including static and dynamic libraries) can matter.
Try with:
g++ Driver.cpp -lGL -lGLU -lglut -o a
(Not sure about the order of the libs, but that looks ok.)
The idea when you build your command line is that if a
requires a symbol from b
, b
must appear after a
in the command line.
The link order problem happens (or not) with GCC/ld for shared libraries depending on (most likely among other things - I'm no expert here) whether the --as-needed
link flag is set or not. (See for instance the before-last item in Gentoo's as-needed transition guide.)
The linking process eliminates un-needed symbols ASAP when --as-needed
is active, which causes problems if the link order is not "correct". This is done to reduce the number of un-necessary dependencies present in final executables.
This doesn't happen (or less so) if --as-needed
is not active - all symbols are kept in that case, and link order doesn't matter as much (more or less - again, I'm no expert.)
Since different distributions use different defaults for that flag, the behavior of GCC might seem inconsistent, but that's just an impression.