【问题标题】:Linking CodeLite and OpenGL with freeglut on Linux在 Linux 上使用 freeglut 链接 CodeLite 和 OpenGL
【发布时间】:2016-01-20 19:03:42
【问题描述】:

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

标头在 /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

这是我的简单代码sn-p:

    #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 文件。我就是无法构建项目。

【问题讨论】:

    标签: c++ linux opengl codelite


    【解决方案1】:

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

    项目设置>链接器

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

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

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多