2014-11-08 49 views
1

我嘗試按照本教程 - >http://kiwwito.com/installing-opengl-glut-libraries-in-ubuntu/安裝OpenGL庫,但是當我嘗試運行程序時,出現此錯誤消息。在Ubuntu中安裝OpenGL/Glut庫

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 <GL/glut.h>程序工作正常。我也試過這個http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/#Building_on_Linux安裝指南,但它不起作用。另外我也嘗試安裝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 

如何解決這些錯誤?

回答

0

對於第一個問題,通過添加-lglut鏈接到過剩。你必須鏈接到你使用的庫。它不足以包含標題。

對於第二個問題,從庫中刪除glfw3。不知道爲什麼那裏。你用的不是glfw。如果教程也使用glfw,那麼另一個選項是安裝它,或者找到一個沒有的教程。

+0

對不起,在手機上。 – 2014-11-08 14:38:19