在 Linux 上将 CodeLite 和 OpenGL 与 freeglut 链接起来

Linking CodeLite and OpenGL with freeglut on Linux

我正在尝试设置 CodeLite IDE 以使用我安装的 OpenGL 库。

headers 在 /usr/include/GL - 这是 ls 的内容:

    freeglut_ext.h  freeglut_std.h  glext.h  gl_mangle.h  glu_mangle.h  glxext.h  glxint.h      glxmd.h     glxtokens.h  freeglut.h      glcorearb.h     gl.h     glu.h        glut.h        glx.h     glx_mangle.h  glxproto.h  internal

这是我的简单代码片段:

    #include <GL/glut.h>

    int main(int argc, char** argv)
    {
        glutInit(&argc, argv);
        return 0;
    }

最后,这是尝试构建项目的输出。

/bin/sh -c '/usr/bin/make -j4 -e -f  Makefile'
----------Building project:[ cpptest1 - Debug ]----------
make[1]: Entering directory '/home/brandon/codelite/cpptest/cpptest1'
/usr/bin/g++  -c  "/home/brandon/codelite/cpptest/cpptest1/main.cpp" -g -O0 -Wall -lglut -lGL -lGLU  -o ./Debug/main.cpp.o -I. -I. -I/usr/include/
/usr/bin/g++ -o ./Debug/cpptest1 @"cpptest1.txt" -L. -L/usr/include/GL  -lGL
./Debug/main.cpp.o: In function `main':
/home/brandon/codelite/cpptest/cpptest1/main.cpp:5: undefined reference to `glutInit'
collect2: error: ld returned 1 exit status
cpptest1.mk:76: recipe for target 'Debug/cpptest1' failed
make[1]: *** [Debug/cpptest1] Error 1
make[1]: Leaving directory '/home/brandon/codelite/cpptest/cpptest1'
Makefile:4: recipe for target 'All' failed
make: *** [All] Error 2
====2 errors, 0 warnings====

请注意,我可以通过在命令行中使用 g++ -o a.out main.cpp -lglut -lGL 创建适当的二进制文件。

我什至可以用CodeLite自己编译main.cpp文件。我只是无法构建项目。

这是一个链接器问题,可以通过以下方式解决:

项目设置 > 链接器

将 GL 和 glut 添加为库并将它们指向您的包含(对于 linux、/usr/include/GL)

此外,确保添加 -lglut 和 -lGL 作为编译器的构建标志。最好将这些添加为全局设置,这样在调试和发布之间更改时就不会破坏配置