C++ g++ 链接器:/usr/lib/libGL.so.1:无法读取符号:操作无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3476869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 12:54:53  来源:igfitidea点击:

g++ linker: /usr/lib/libGL.so.1: could not read symbols: Invalid operation

c++opengllinkerglut

提问by phimuemue

I'm trying to build a very simple OpenGL-app under Ubuntu 10.04 (I have a 32 bit system).

我正在尝试在 Ubuntu 10.04(我有一个 32 位系统)下构建一个非常简单的 OpenGL 应用程序。

When I'm trying to compile the file, I get the error message:

当我尝试编译文件时,我收到错误消息:

g++ -L/usr/lib simple.cpp -lglut
/usr/bin/ld: /tmp/ccoPczAo.o: undefined reference to symbol 'glEnd'
/usr/bin/ld: note: 'glEnd' is defined in DSO //usr/lib/libGL.so.1 so try adding it to the linker command line
//usr/lib/libGL.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

Does anybody know what I'm doing wrong?

有谁知道我做错了什么?

回答by jcoder

You need to include the opengl library on the command line as well as the glut library/. Try adding -lGL to the end of your command line

您需要在命令行中包含 opengl 库以及 glut 库/。尝试将 -lGL 添加到命令行的末尾

g++ -L/usr/lib simple.cpp -lglut -lGL

回答by mifthi

compile with

编译

g++ main.cpp -o main.bin -lGL -lGLU -lglut

or Try the following make file from OpenGL primerit is very compact. This one helped me to run my Hello world OpenGL. Thanks to OpenGL Primer

或尝试以下来自OpenGL 入门的make 文件,它非常紧凑。这个帮助我运行我的 Hello world OpenGL。感谢OpenGL 入门

CC = g++
SRC = main.cpp imageloader.cpp
LIBS = -lGL -lGLU -lglut
EXEC = cube.bin

all:
       $(CC) $(SRC) -o $(EXEC) $(LIBS)

clean:
       rm -rf $(EXEC) *~