0

我尝试使用 g++ 命令编译我的 c++/opengl-project。(我需要这个,因为我想在每个目标系统上使用第二个自写程序重新编译它。)

但是当我执行时:

g++ -Iinclude -Isrc $(pkg-config --cflags freetype2) -L/usr/X11R6/lib -L/usr/lib $(pkg-config --libs glew) -lglut $(pkg-config --libs glu) $(pkg-config --libs freetype2) main.cpp  (some more source files) src/Vec4.cpp

我为 gl/glu/glut/glew-functions 得到了很多“未定义的引用”,所以我猜这些库会失败:

/tmp/ccUm2dEl.o: In function `Box::render()':
Box.cpp:(.text+0x6e8): undefined reference to `glEnable'
Box.cpp:(.text+0x72c): undefined reference to `glBindTexture'
Box.cpp:(.text+0x736): undefined reference to `glBegin'
...
TextureManager.cpp:(.text+0x23b): undefined reference to `glTexParameteri'
TextureManager.cpp:(.text+0x295): undefined reference to `glTexImage2D'
collect2: ld gab 1 als Ende-Status zurück

我做了一些研究,但根据我发现上面的命令应该是正确的。我也检查了 pkg-config-calls,它们似乎工作。在我尝试 g++ 命令之前,我使用 Codeblocks IDE 编译它并且它工作。这是我的设置:

编译器设置|其他选项中:

`pkg-config --cflags freetype2`

链接器设置|链接库中:

glut

链接器设置|其他链接器选项中:

`pkg-config --libs glu`
`pkg-config --libs glew`
`pkg-config --libs freetype2`

搜索目录|编译器中:

include
src

我的系统(Ubuntu Precise):

$ uname -a
Linux andromeda 3.2.0-32-generic #51-Ubuntu SMP Wed Sep 26 21:33:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

$ g++ -dumpversion
4.6

glxinfo
GLX version: 1.4
OpenGL version string: 4.2.0 NVIDIA 304.43

Codeblocks-version: 10.04

谢谢指教

4

1 回答 1

1

问题很可能是您以错误的顺序链接。GNU 链接器希望它的库以相反的顺序排列,所以如果你将链接器库放在命令行的最后,它应该会更好。

于 2012-11-03T15:36:22.507 回答