Opengl linux undefined reference to basic functions

前端 未结 1 630
心在旅途
心在旅途 2020-12-09 13:22

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

相关标签:
1条回答
  • 2020-12-09 14:00

    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.

    0 讨论(0)
提交回复
热议问题