Ubuntu 包含头文件,但仍然无法调用函数 我试图在UBUTUT1204下用C++编写绘图程序。OpenGL应用于我的代码(cc.cpp)。我已经包含了必要的头文件,但是openGL函数仍然不能使用

Ubuntu 包含头文件,但仍然无法调用函数 我试图在UBUTUT1204下用C++编写绘图程序。OpenGL应用于我的代码(cc.cpp)。我已经包含了必要的头文件,但是openGL函数仍然不能使用,ubuntu,c++,Ubuntu,C++,这是包含代码 #include <GL/freeglut.h> #include <GL/gl.h> #include <GL/glu.h> #include <stdio.h> #include <math.h> #include <cstdlib> 有人能找到解决办法吗?我会很感激的 您需要在g++中添加标志,以便在-l选项中包含必要的库。 它可能类似于它的显示方式或 试试这个- g++cc.cpp-lGL-lglu

这是包含代码

#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <math.h>
#include <cstdlib> 

有人能找到解决办法吗?我会很感激的

您需要在
g++
中添加标志,以便在
-l
选项中包含必要的库。 它可能类似于它的显示方式或

试试这个-


g++cc.cpp-lGL-lglut

欢迎使用超级用户!我们是计算机硬件/软件问题的专业网站。编程不属于常见问题解答中定义的范围,但我已投票将其转移到Stackoverflow,程序员网站。请不要在那里张贴,这个问题将自然移动头文件是没有任何关系的链接器。
/tmp/ccsiISvK.o: In function `initGL()':
cc.cpp:(.text+0xe): undefined reference to `glMatrixMode'
cc.cpp:(.text+0x13): undefined reference to `glLoadIdentity'
cc.cpp:(.text+0x49): undefined reference to `glOrtho'
cc.cpp:(.text+0x55): undefined reference to `glMatrixMode'
cc.cpp:(.text+0x5a): undefined reference to `glLoadIdentity'
cc.cpp:(.text+0x82): undefined reference to `glClearColor'
cc.cpp:(.text+0x87): undefined reference to `glGetError'
cc.cpp:(.text+0x9b): undefined reference to `gluErrorString'
/tmp/ccsiISvK.o: In function `render()':
cc.cpp:(.text+0x124): undefined reference to `glClear'
cc.cpp:(.text+0x130): undefined reference to `glBegin'
cc.cpp:(.text+0x14f): undefined reference to `glColor3f'
cc.cpp:(.text+0x18b): undefined reference to `glVertex2f'
cc.cpp:(.text+0x1b0): undefined reference to `glEnd'
cc.cpp:(.text+0x1b5): undefined reference to `glutSwapBuffers'
/tmp/ccsiISvK.o: In function `runMainLoop(int)':
cc.cpp:(.text+0x1f7): undefined reference to `glutTimerFunc'
/tmp/ccsiISvK.o: In function `main':
cc.cpp:(.text+0x214): undefined reference to `glutInit'
cc.cpp:(.text+0x228): undefined reference to `glutInitContextVersion'
cc.cpp:(.text+0x234): undefined reference to `glutInitDisplayMode'
cc.cpp:(.text+0x248): undefined reference to `glutInitWindowSize'
cc.cpp:(.text+0x254): undefined reference to `glutCreateWindow'
cc.cpp:(.text+0x27f): undefined reference to `glutDisplayFunc'
cc.cpp:(.text+0x29b): undefined reference to `glutTimerFunc'
cc.cpp:(.text+0x2a0): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status