Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Ubuntu中安装OpenGL/Glut库_C++_Eclipse_Opengl - Fatal编程技术网

C++ 在Ubuntu中安装OpenGL/Glut库

C++ 在Ubuntu中安装OpenGL/Glut库,c++,eclipse,opengl,C++,Eclipse,Opengl,我试图按照本教程->安装ubuntu的OpenGL库,但当我尝试运行示例程序时,会收到此错误消息 test2.c:(.text+0x1d): undefined reference to `glClearColor' test2.c:(.text+0x27): undefined reference to `glClear' test2.c:(.text+0x2c): undefined reference to `glFlush' /tmp/ccNGbmFL.o: In function `m

我试图按照本教程->安装ubuntu的OpenGL库,但当我尝试运行示例程序时,会收到此错误消息

test2.c:(.text+0x1d): undefined reference to `glClearColor'
test2.c:(.text+0x27): undefined reference to `glClear'
test2.c:(.text+0x2c): undefined reference to `glFlush'
/tmp/ccNGbmFL.o: In function `main':
test2.c:(.text+0x50): undefined reference to `glutInit'
test2.c:(.text+0x5a): undefined reference to `glutInitDisplayMode'
test2.c:(.text+0x69): undefined reference to `glutInitWindowPosition'
test2.c:(.text+0x78): undefined reference to `glutInitWindowSize'
test2.c:(.text+0x82): undefined reference to `glutCreateWindow'
test2.c:(.text+0x8c): undefined reference to `glutDisplayFunc'
test2.c:(.text+0x91): undefined reference to `glutMainLoop'
当我删除这些函数并只保留
#include
时,程序运行正常。我也试过这个安装指南,但它不太管用。我还尝试安装eclipse并在C++链接器中添加这些库。Eclipse控制台输出为:

16:02:45 **** Incremental Build of configuration Debug for project opengl_glut ****
make all 
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: opengl_glut
Invoking: Cross G++ Linker
g++  -o "opengl_glut"  ./main.o   -lglut -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread -lglfw3 -lGLU
/usr/bin/ld: cannot find -lglfw3
makefile:44: recipe for target 'opengl_glut' failed
collect2: error: ld returned 1 exit status
make: *** [opengl_glut] Error 1

如何修复这些错误?

对于您的第一个问题,请通过添加
-lglut
链接到glut。您必须链接到您使用的库。仅仅包含标题是不够的


对于第二个问题,请从库中删除glfw3。不知道为什么会这样。您使用的是glut而不是glfw。如果教程也使用glfw,那么另一个选项是安装它,或者在移动站点上查找不使用glfw的教程。

为简洁起见,非常抱歉。