【发布时间】:2012-11-03 15:31:24
【问题描述】:
我尝试使用 g++ 命令编译我的 c++/opengl 项目。 (我需要这个,因为我想在每个目标系统上使用第二个自写程序重新编译它。)
但是当我执行时:
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 精确):
$ 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
感谢您的建议
【问题讨论】:
-
将您的文件(.cpp 和 .o)放在您在命令行上链接到的库之前。
-
我没有看到 libGL 被添加。尝试在 X11 库之后添加
-lGL。 -
顺便说一下libGL是用
pkg-config --libs glu添加的
标签: opengl g++ linker-errors glew