【问题标题】:C++ with GLUT static compile on linux在 Linux 上使用 GLUT 静态编译的 C++
【发布时间】:2015-12-05 17:47:05
【问题描述】:

我正在尝试将简单的程序编译为独立的可执行文件,以便将其发送给我的朋友。但我正面临 GLUT 依赖的问题。我试过的命令是:

g++ triangle.cpp -static -lglut -lGLU -lGL -lm

我得到了这个错误:

/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status

当我尝试使用 Mingw64 时,我得到了这个:

    i686-w64-mingw32-g++ triangle.cpp -static -lglut -lGLU -lGL -lm -o test.exe

    triangle.cpp:9:21: fatal error: GL/glut.h: No such file or directory
 #include <GL/glut.h>
                     ^
compilation terminated.

我的包括

#include <vector>
#include <cstdio>
#include <GL/glut.h>
#include <math.h>
#include <string>
#include <sstream>

【问题讨论】:

  • 您必须告诉编译器在哪里可以找到头文件(通常是-I 选项)和链接器在哪里可以找到库(通常是-L 选项)。
  • 你能告诉我具体是怎么做的吗?
  • 阅读编译器的文档。首先查找我提到的两个选项。
  • a 这样做了:g++ triangle.cpp -static -L /usr/include/GL/glut.h -L /usr/include/GL/glu.h -lm -L /usr/include/GL/gl.h,我给了我很多未定义的参考错误。例如triangle.cpp:(.text+0x79b): undefined reference to glClear'`

标签: c++ linux g++ glut


【解决方案1】:
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status

您似乎没有安装 GLUT 库。 对于有 aptitude 的 GNU linux,请尝试

apt-get update
apt-cache search freeglut

获取包含 freeglut 的所有库的列表。 我认为(不完全确定)您需要安装 freeglut3-dev

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 2011-02-13
    相关资源
    最近更新 更多