链接 openGL 库失败,因为它无法打开 libgl.so ...但它就在那里
Linking an openGL library fails because it can't open libgl.so ... but it's right there
当我尝试使用 openGL 制作一个对我来说非常难以捉摸的 c++ 项目时,我遇到了以下错误。当我运行生成文件时,我得到以下内容:
g++ -c init.cpp
g++ -o executable console.o init.o -lglut -lgl
/usr/bin/x86_64-linux-gnu-ld: cannot find -lgl
collect2: error: ld returned 1 exit status
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 1
好的,当然。找不到图书馆。我将这一行添加到我的生成文件中以进行调查
ld -lglut -lgl --verbose
我得到以下内容,其他事情
attempt to open //usr/local/lib/x86_64-linux-gnu/libglut.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libglut.a failed
attempt to open //lib/x86_64-linux-gnu/libglut.so failed
attempt to open //lib/x86_64-linux-gnu/libglut.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libglut.so succeeded
-lglut (//usr/lib/x86_64-linux-gnu/libglut.so)
attempt to open //usr/local/lib/x86_64-linux-gnu/libgl.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libgl.a failed
attempt to open //lib/x86_64-linux-gnu/libgl.so failed
attempt to open //lib/x86_64-linux-gnu/libgl.a failed
attempt to open //usr/lib/x86_64-linux-gnu/libgl.so failed
attempt to open //usr/lib/x86_64-linux-gnu/libgl.a failed
attempt to open //usr/lib/x86_64-linux-gnu64/libgl.so failed
attempt to open //usr/lib/x86_64-linux-gnu64/libgl.a failed
attempt to open //usr/local/lib64/libgl.so failed
attempt to open //usr/local/lib64/libgl.a failed
attempt to open //lib64/libgl.so failed
attempt to open //lib64/libgl.a failed
attempt to open //usr/lib64/libgl.so failed
attempt to open //usr/lib64/libgl.a failed
attempt to open //usr/local/lib/libgl.so failed
attempt to open //usr/local/lib/libgl.a failed
attempt to open //lib/libgl.so failed
attempt to open //lib/libgl.a failed
attempt to open //usr/lib/libgl.so failed
attempt to open //usr/lib/libgl.a failed
attempt to open //usr/x86_64-linux-gnu/lib64/libgl.so failed
attempt to open //usr/x86_64-linux-gnu/lib64/libgl.a failed
attempt to open //usr/x86_64-linux-gnu/lib/libgl.so failed
attempt to open //usr/x86_64-linux-gnu/lib/libgl.a failed
ld: cannot find -lgl
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 1
因此,当我在线查找时,似乎大多数这些错误都与ld没有在正确的目录中查找有关,但是ld正在查找正确的目录,因为此尝试实际上针对正确的位置:
attempt to open //usr/lib/x86_64-linux-gnu/libgl.so failed
我不仅在该目录中有该文件,而且上次读取它是在 8:00,3 小时前,因为我能够以某种方式更早地链接它,即使我没有更改与链接相关的任何内容
这是我正在使用的生成文件。
cc=g++
edit: init.o console.o
ld -lglut -lgl --verbose
$(cc) -o executable console.o init.o -lglut -lgl
init.o: init.cpp
$(cc) -c init.cpp
console.o: console.cpp
$(cc) -c console.cpp
clean:
rm init.o console.o executable
这是init.cpp:
#include <cstdlib>
//#include </usr/include/GL/glew.h>
#include <GL/freeglut.h>
//#include <GL/gl.h>
void consoleDisplay(int a);
void renderCB(void);
void resizeCB(int W, int H);
void idleCB(void);
void timerCB(int Value);
void glutInitErrorFunc(void (*callback)(const char *fmt, va_list ap) );
void glutInitWarningFunc(void (*callback)(const char *fmt, va_list ap) );
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitWindowSize(500, 500);
glutInitWindowPosition(300, 300);
int windowLeft= glutGet(GLUT_WINDOW_X);
int windowWidth= glutGet(GLUT_WINDOW_WIDTH);
consoleDisplay(windowLeft);
consoleDisplay(windowWidth);
int winID = glutCreateWindow("Hello again, world.");
glutReshapeFunc(resizeCB);
glutDisplayFunc(renderCB);
glutIdleFunc(idleCB);
glutTimerFunc(0, timerCB ,0);
glutMainLoop();
return 0;
}
void renderCB(void){
//doActualOpenGLStuffHere()
glutSwapBuffers();
glutPostRedisplay();
}
void resizeCB(int W, int H){
glViewport(0, 0, W, H);
}
void idleCB(void){
glutPostRedisplay();
}
void timerCB(int Value){
}
最后是控制台.cpp:
#include <iostream>
void consoleDisplay(int a){
std::cout << a << "n";
}
大多数 Linux 文件系统都区分大小写,因此当您在系统库目录中有一个libGL.so
并且ld
询问文件系统是否存在libgl.so
时,它会说不,链接将失败。
解决方案:确保要传递到的库名称ld
与磁盘上的大写相匹配:
$(cc) -o executable console.o init.o -lglut -lGL
^^ note the caps
相关文章:
- 如何使用ndk-build.cmd构建Android.so文件
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- CLANG格式在缺少libtinfo.so.5库中不起作用
- C++ 运行时链接器错误 (liblog4cpp.so.5) Eclipse
- 使 ld 忽略来自 /etc/ld.so.conf 的目录
- N-API include an .so or dll
- 加载共享库时C++错误:libopencv_ximgproc.so.4.4
- 如何从构建 libgpio.so 的生成文件构建libgpio.a
- 用于构建 cuda .so 文件(共享库)的生成文件
- 无法从 SO 文件调用 SO 文件的函数 - C++生成文件
- 共享库 (.so) 没有扩展名的 Linux 可执行文件之间的区别?
- 在jupyter notebook和google colab中使用.so
- 如何在 C++ 的 .so 文件中包含库
- JNI,使用两个 .so 文件时出错,其中一个文件需要另一个文件
- OpenVINO - 推理库插件 libMKLDNNPlugin.so 无法解析依赖关系
- 链接 openGL 库失败,因为它无法打开 libgl.so ...但它就在那里
- ATI 专有驱动程序重命名 libGL.so
- Qt 5.4.0 在 libGL.so.1 上安装失败,但 libgl-dev 和 ibglu-dev 已经安装
- 我的文件链接到libGL.so.1