在ubuntu终端,g++怎么编译含系统不带头文件的C++程序

我是一只鱼 发布于 2012/02/13 12:00
阅读 3K+
收藏 0

本人遇到了一个困扰我很久的一个问题:

我有一个C++程序,含有自己编写的头文件headm.h和c文件headm.cc,还有主体文件mainc.cc文件,这三个文件在XP的VC,VS里面都可以编译和运行,但是到了ubuntu下g++编译就缺少头文件,我把头文件加入到系统文件夹也不行,我的编译命令是:

g++ mainc.cc -o mainc,出现头文件里面的函数不能解析,请哪位高手可以提点一下,怎么样才能使他可以在ubuntu下进行编译,或者用哪条命令进行编译?

加载中
0
six
six

你是否编译了你的headm.cc文件?

g++ mainc.cc headm.cc -o mainc

0
leo108
leo108
贴一下具体报错信息
0
我是一只鱼
我是一只鱼

引用来自“six”的答案

你是否编译了你的headm.cc文件?

g++ mainc.cc headm.cc -o mainc

这种方法试过了,没编译成功,头文件找不到。
0
我是一只鱼
我是一只鱼

引用来自“leo108”的答案

贴一下具体报错信息

好的,我来个具体的吧,我有3个文件transformation.c  glm.c glm.h,首先声明3个文件在VC 和VS下编译和运行都没错。我进行的编译命令是:g++ transformation.c glm.c -o transformation

出现如下错误:

transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:33: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:40: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c:46: warning: deprecated conversion from string constant to ‘char*’
transformation.c: In function ‘void drawmodel()’:
transformation.c:164: warning: deprecated conversion from string constant to ‘char*’
transformation.c: In function ‘void main_display()’:
transformation.c:333: warning: deprecated conversion from string constant to ‘char*’
transformation.c:334: warning: deprecated conversion from string constant to ‘char*’
transformation.c:335: warning: deprecated conversion from string constant to ‘char*’
transformation.c:336: warning: deprecated conversion from string constant to ‘char*’
transformation.c: In function ‘void screen_menu(int)’:
transformation.c:530: warning: deprecated conversion from string constant to ‘char*’
transformation.c:533: warning: deprecated conversion from string constant to ‘char*’
transformation.c:536: warning: deprecated conversion from string constant to ‘char*’
transformation.c:539: warning: deprecated conversion from string constant to ‘char*’
transformation.c:542: warning: deprecated conversion from string constant to ‘char*’
transformation.c:545: warning: deprecated conversion from string constant to ‘char*’
transformation.c:548: warning: deprecated conversion from string constant to ‘char*’
transformation.c: In function ‘void command_display()’:
transformation.c:599: warning: deprecated conversion from string constant to ‘char*’
transformation.c:600: warning: deprecated conversion from string constant to ‘char*’
transformation.c:601: warning: deprecated conversion from string constant to ‘char*’
transformation.c:602: warning: deprecated conversion from string constant to ‘char*’
transformation.c:603: warning: deprecated conversion from string constant to ‘char*’
transformation.c:604: warning: deprecated conversion from string constant to ‘char*’
transformation.c:605: warning: deprecated conversion from string constant to ‘char*’
transformation.c:606: warning: deprecated conversion from string constant to ‘char*’
transformation.c:607: warning: deprecated conversion from string constant to ‘char*’
transformation.c:608: warning: deprecated conversion from string constant to ‘char*’
transformation.c:609: warning: deprecated conversion from string constant to ‘char*’
transformation.c:610: warning: deprecated conversion from string constant to ‘char*’
transformation.c:611: warning: deprecated conversion from string constant to ‘char*’
transformation.c:612: warning: deprecated conversion from string constant to ‘char*’
transformation.c:613: warning: deprecated conversion from string constant to ‘char*’
transformation.c:614: warning: deprecated conversion from string constant to ‘char*’
transformation.c:632: warning: deprecated conversion from string constant to ‘char*’
glm.c: In function ‘GLvoid glmFirstPass(GLMmodel*, FILE*)’:
glm.c:466: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccTzJ7Ag.o: In function `setfont(char*, int)':
transformation.c:(.text+0xc): undefined reference to `glutBitmapHelvetica10'
transformation.c:(.text+0x33): undefined reference to `glutBitmapHelvetica12'
transformation.c:(.text+0x4c): undefined reference to `glutBitmapHelvetica18'
transformation.c:(.text+0x6f): undefined reference to `glutBitmapTimesRoman10'
transformation.c:(.text+0x7f): undefined reference to `glutBitmapTimesRoman24'
transformation.c:(.text+0xa2): undefined reference to `glutBitmap8By13'
transformation.c:(.text+0xc5): undefined reference to `glutBitmap9By15'
/tmp/ccTzJ7Ag.o: In function `drawstr(unsigned int, unsigned int, char*, ...)':
transformation.c:(.text+0x121): undefined reference to `glRasterPos2i'
transformation.c:(.text+0x14c): undefined reference to `glutBitmapCharacter'
/tmp/ccTzJ7Ag.o: In function `cell_draw(_cell*)':
transformation.c:(.text+0x19a): undefined reference to `glColor3ub'
transformation.c:(.text+0x1c4): undefined reference to `glColor3ub'
transformation.c:(.text+0x1fe): undefined reference to `glColor3ub'
/tmp/ccTzJ7Ag.o: In function `drawaxes()':
transformation.c:(.text+0x3c4): undefined reference to `glColor3ub'
transformation.c:(.text+0x3d0): undefined reference to `glBegin'
transformation.c:(.text+0x3ef): undefined reference to `glVertex3f'
transformation.c:(.text+0x40e): undefined reference to `glVertex3f'
transformation.c:(.text+0x42d): undefined reference to `glVertex3f'
transformation.c:(.text+0x44c): undefined reference to `glVertex3f'
transformation.c:(.text+0x46b): undefined reference to `glVertex3f'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x48a): more undefined references to `glVertex3f' follow
/tmp/ccTzJ7Ag.o: In function `drawaxes()':
transformation.c:(.text+0x4cd): undefined reference to `glEnd'
transformation.c:(.text+0x4d9): undefined reference to `glBegin'
transformation.c:(.text+0x4f8): undefined reference to `glVertex3f'
transformation.c:(.text+0x517): undefined reference to `glVertex3f'
transformation.c:(.text+0x536): undefined reference to `glVertex3f'
transformation.c:(.text+0x555): undefined reference to `glVertex3f'
transformation.c:(.text+0x574): undefined reference to `glVertex3f'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x593): more undefined references to `glVertex3f' follow
/tmp/ccTzJ7Ag.o: In function `drawaxes()':
transformation.c:(.text+0x5d6): undefined reference to `glEnd'
transformation.c:(.text+0x5e2): undefined reference to `glBegin'
transformation.c:(.text+0x601): undefined reference to `glVertex3f'
transformation.c:(.text+0x620): undefined reference to `glVertex3f'
transformation.c:(.text+0x63f): undefined reference to `glVertex3f'
transformation.c:(.text+0x65e): undefined reference to `glVertex3f'
transformation.c:(.text+0x67d): undefined reference to `glVertex3f'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x69c): more undefined references to `glVertex3f' follow
/tmp/ccTzJ7Ag.o: In function `drawaxes()':
transformation.c:(.text+0x6df): undefined reference to `glEnd'
transformation.c:(.text+0x6fb): undefined reference to `glColor3ub'
transformation.c:(.text+0x71a): undefined reference to `glRasterPos3f'
transformation.c:(.text+0x729): undefined reference to `glutBitmapHelvetica12'
transformation.c:(.text+0x72e): undefined reference to `glutBitmapCharacter'
transformation.c:(.text+0x74d): undefined reference to `glRasterPos3f'
transformation.c:(.text+0x75c): undefined reference to `glutBitmapHelvetica12'
transformation.c:(.text+0x761): undefined reference to `glutBitmapCharacter'
transformation.c:(.text+0x780): undefined reference to `glRasterPos3f'
transformation.c:(.text+0x78f): undefined reference to `glutBitmapHelvetica12'
transformation.c:(.text+0x794): undefined reference to `glutBitmapCharacter'
/tmp/ccTzJ7Ag.o: In function `main_reshape(int, int)':
transformation.c:(.text+0xc2c): undefined reference to `glViewport'
transformation.c:(.text+0xc38): undefined reference to `glMatrixMode'
transformation.c:(.text+0xc3d): undefined reference to `glLoadIdentity'
transformation.c:(.text+0xc5d): undefined reference to `gluOrtho2D'
transformation.c:(.text+0xc69): undefined reference to `glMatrixMode'
transformation.c:(.text+0xc6e): undefined reference to `glLoadIdentity'
transformation.c:(.text+0xcd8): undefined reference to `glutSetWindow'
transformation.c:(.text+0xcec): undefined reference to `glutPositionWindow'
transformation.c:(.text+0xd04): undefined reference to `glutReshapeWindow'
transformation.c:(.text+0xd11): undefined reference to `glutSetWindow'
transformation.c:(.text+0xd29): undefined reference to `glutPositionWindow'
transformation.c:(.text+0xd41): undefined reference to `glutReshapeWindow'
transformation.c:(.text+0xd4e): undefined reference to `glutSetWindow'
transformation.c:(.text+0xd66): undefined reference to `glutPositionWindow'
transformation.c:(.text+0xd8a): undefined reference to `glutReshapeWindow'
/tmp/ccTzJ7Ag.o: In function `main_display()':
transformation.c:(.text+0xdba): undefined reference to `glClearColor'
transformation.c:(.text+0xdc6): undefined reference to `glClear'
transformation.c:(.text+0xde2): undefined reference to `glColor3ub'
transformation.c:(.text+0xe57): undefined reference to `glutSwapBuffers'
/tmp/ccTzJ7Ag.o: In function `world_reshape(int, int)':
transformation.c:(.text+0xf31): undefined reference to `glViewport'
transformation.c:(.text+0xf3d): undefined reference to `glMatrixMode'
transformation.c:(.text+0xf42): undefined reference to `glLoadIdentity'
transformation.c:(.text+0xf70): undefined reference to `gluPerspective'
transformation.c:(.text+0xf7c): undefined reference to `glMatrixMode'
transformation.c:(.text+0xf81): undefined reference to `glLoadIdentity'
transformation.c:(.text+0xfa0): undefined reference to `glTranslatef'
transformation.c:(.text+0xfc8): undefined reference to `glRotatef'
transformation.c:(.text+0xff0): undefined reference to `glClearColor'
transformation.c:(.text+0xffc): undefined reference to `glEnable'
transformation.c:(.text+0x1008): undefined reference to `glEnable'
/tmp/ccTzJ7Ag.o: In function `world_display()':
transformation.c:(.text+0x1091): undefined reference to `glClear'
transformation.c:(.text+0x10a8): undefined reference to `glEnable'
transformation.c:(.text+0x10ad): undefined reference to `glPushMatrix'
transformation.c:(.text+0x10b9): undefined reference to `glMultMatrixd'
transformation.c:(.text+0x10d4): undefined reference to `glLightfv'
transformation.c:(.text+0x10d9): undefined reference to `glPopMatrix'
transformation.c:(.text+0x10ea): undefined reference to `glDisable'
transformation.c:(.text+0x10ef): undefined reference to `glPushMatrix'
transformation.c:(.text+0x10fb): undefined reference to `glMultMatrixd'
transformation.c:(.text+0x1116): undefined reference to `glLightfv'
transformation.c:(.text+0x111b): undefined reference to `glPushMatrix'
transformation.c:(.text+0x1137): undefined reference to `glColor3ub'
transformation.c:(.text+0x1143): undefined reference to `glBegin'
transformation.c:(.text+0x1162): undefined reference to `glVertex3f'
transformation.c:(.text+0x1187): undefined reference to `glVertex3f'
transformation.c:(.text+0x11b2): undefined reference to `glVertex3f'
transformation.c:(.text+0x11dd): undefined reference to `glVertex3f'
transformation.c:(.text+0x1202): undefined reference to `glVertex3f'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x122d): more undefined references to `glVertex3f' follow
/tmp/ccTzJ7Ag.o: In function `world_display()':
transformation.c:(.text+0x1282): undefined reference to `glEnd'
transformation.c:(.text+0x129e): undefined reference to `glColor3ub'
transformation.c:(.text+0x12c9): undefined reference to `glRasterPos3f'
transformation.c:(.text+0x12d8): undefined reference to `glutBitmapHelvetica12'
transformation.c:(.text+0x12dd): undefined reference to `glutBitmapCharacter'
transformation.c:(.text+0x12f9): undefined reference to `glColor3ub'
transformation.c:(.text+0x1318): undefined reference to `glScalef'
transformation.c:(.text+0x1322): undefined reference to `glPopMatrix'
transformation.c:(.text+0x1342): undefined reference to `glMultMatrixd'
transformation.c:(.text+0x1361): undefined reference to `glColor3f'
transformation.c:(.text+0x136d): undefined reference to `glBegin'
transformation.c:(.text+0x1389): undefined reference to `glVertex3i'
transformation.c:(.text+0x13a5): undefined reference to `glVertex3i'
transformation.c:(.text+0x13c1): undefined reference to `glVertex3i'
transformation.c:(.text+0x13dd): undefined reference to `glVertex3i'
transformation.c:(.text+0x13e2): undefined reference to `glEnd'
transformation.c:(.text+0x13fe): undefined reference to `glColor3ub'
transformation.c:(.text+0x140a): undefined reference to `glBegin'
transformation.c:(.text+0x1426): undefined reference to `glVertex3i'
transformation.c:(.text+0x1442): undefined reference to `glVertex3i'
transformation.c:(.text+0x145e): undefined reference to `glVertex3i'
transformation.c:(.text+0x147a): undefined reference to `glVertex3i'
transformation.c:(.text+0x1496): undefined reference to `glVertex3i'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x14b2): more undefined references to `glVertex3i' follow
/tmp/ccTzJ7Ag.o: In function `world_display()':
transformation.c:(.text+0x14ef): undefined reference to `glEnd'
transformation.c:(.text+0x14fb): undefined reference to `glEnable'
transformation.c:(.text+0x150f): undefined reference to `glBlendFunc'
transformation.c:(.text+0x1537): undefined reference to `glColor4f'
transformation.c:(.text+0x1543): undefined reference to `glBegin'
transformation.c:(.text+0x155f): undefined reference to `glVertex3i'
transformation.c:(.text+0x157b): undefined reference to `glVertex3i'
transformation.c:(.text+0x1597): undefined reference to `glVertex3i'
transformation.c:(.text+0x15b3): undefined reference to `glVertex3i'
transformation.c:(.text+0x15b8): undefined reference to `glEnd'
transformation.c:(.text+0x15c4): undefined reference to `glDisable'
transformation.c:(.text+0x15c9): undefined reference to `glPopMatrix'
transformation.c:(.text+0x15ce): undefined reference to `glutSwapBuffers'
/tmp/ccTzJ7Ag.o: In function `screen_reshape(int, int)':
transformation.c:(.text+0x161f): undefined reference to `glViewport'
transformation.c:(.text+0x162b): undefined reference to `glMatrixMode'
transformation.c:(.text+0x1630): undefined reference to `glLoadIdentity'
transformation.c:(.text+0x165e): undefined reference to `gluPerspective'
transformation.c:(.text+0x1672): undefined reference to `glGetDoublev'
transformation.c:(.text+0x167e): undefined reference to `glMatrixMode'
transformation.c:(.text+0x1683): undefined reference to `glLoadIdentity'
transformation.c:(.text+0x16f3): undefined reference to `gluLookAt'
transformation.c:(.text+0x1729): undefined reference to `glRotatef'
transformation.c:(.text+0x174a): undefined reference to `glTranslatef'
transformation.c:(.text+0x176d): undefined reference to `glTranslatef'
transformation.c:(.text+0x1798): undefined reference to `glRotatef'
transformation.c:(.text+0x17b9): undefined reference to `glScalef'
transformation.c:(.text+0x17cd): undefined reference to `glGetDoublev'
transformation.c:(.text+0x17f5): undefined reference to `glClearColor'
transformation.c:(.text+0x1801): undefined reference to `glEnable'
transformation.c:(.text+0x180d): undefined reference to `glEnable'
transformation.c:(.text+0x1819): undefined reference to `glEnable'
/tmp/ccTzJ7Ag.o: In function `screen_display()':
transformation.c:(.text+0x1831): undefined reference to `glClear'
transformation.c:(.text+0x183b): undefined reference to `glutSwapBuffers'
/tmp/ccTzJ7Ag.o: In function `command_reshape(int, int)':
transformation.c:(.text+0x1927): undefined reference to `glViewport'
transformation.c:(.text+0x1933): undefined reference to `glMatrixMode'
transformation.c:(.text+0x1938): undefined reference to `glLoadIdentity'
transformation.c:(.text+0x1958): undefined reference to `gluOrtho2D'
transformation.c:(.text+0x1964): undefined reference to `glMatrixMode'
transformation.c:(.text+0x1969): undefined reference to `glLoadIdentity'
transformation.c:(.text+0x1991): undefined reference to `glClearColor'
/tmp/ccTzJ7Ag.o: In function `command_display()':
transformation.c:(.text+0x19a5): undefined reference to `glClear'
transformation.c:(.text+0x1a5a): undefined reference to `glColor3ub'
transformation.c:(.text+0x1cb8): undefined reference to `glColor3ub'
transformation.c:(.text+0x1cd9): undefined reference to `glutSwapBuffers'
/tmp/ccTzJ7Ag.o: In function `redisplay_all()':
transformation.c:(.text+0x1fc8): undefined reference to `glutSetWindow'
transformation.c:(.text+0x1fcd): undefined reference to `glutPostRedisplay'
transformation.c:(.text+0x1fda): undefined reference to `glutSetWindow'
transformation.c:(.text+0x1ff7): undefined reference to `glutPostRedisplay'
transformation.c:(.text+0x2004): undefined reference to `glutSetWindow'
transformation.c:(.text+0x2021): undefined reference to `glutPostRedisplay'
/tmp/ccTzJ7Ag.o: In function `main':
transformation.c:(.text+0x2038): undefined reference to `glutInitDisplayMode'
transformation.c:(.text+0x204c): undefined reference to `glutInitWindowSize'
transformation.c:(.text+0x2060): undefined reference to `glutInitWindowPosition'
transformation.c:(.text+0x2072): undefined reference to `glutInit'
transformation.c:(.text+0x207e): undefined reference to `glutCreateWindow'
transformation.c:(.text+0x208f): undefined reference to `glutReshapeFunc'
transformation.c:(.text+0x209b): undefined reference to `glutDisplayFunc'
transformation.c:(.text+0x20a7): undefined reference to `glutKeyboardFunc'
transformation.c:(.text+0x20d4): undefined reference to `glutCreateSubWindow'
transformation.c:(.text+0x20e5): undefined reference to `glutReshapeFunc'
transformation.c:(.text+0x20f1): undefined reference to `glutDisplayFunc'
transformation.c:(.text+0x20fd): undefined reference to `glutKeyboardFunc'
transformation.c:(.text+0x2109): undefined reference to `glutCreateMenu'
transformation.c:(.text+0x211d): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x2129): undefined reference to `glutAttachMenu'
transformation.c:(.text+0x2156): undefined reference to `glutCreateSubWindow'
transformation.c:(.text+0x2167): undefined reference to `glutReshapeFunc'
transformation.c:(.text+0x2173): undefined reference to `glutDisplayFunc'
transformation.c:(.text+0x217f): undefined reference to `glutKeyboardFunc'
transformation.c:(.text+0x218b): undefined reference to `glutCreateMenu'
transformation.c:(.text+0x219f): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x21b3): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x21c7): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x21db): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x21ef): undefined reference to `glutAddMenuEntry'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x2203): more undefined references to `glutAddMenuEntry' follow
/tmp/ccTzJ7Ag.o: In function `main':
transformation.c:(.text+0x224b): undefined reference to `glutAttachMenu'
transformation.c:(.text+0x2278): undefined reference to `glutCreateSubWindow'
transformation.c:(.text+0x2289): undefined reference to `glutReshapeFunc'
transformation.c:(.text+0x2295): undefined reference to `glutDisplayFunc'
transformation.c:(.text+0x22a1): undefined reference to `glutMotionFunc'
transformation.c:(.text+0x22ad): undefined reference to `glutMouseFunc'
transformation.c:(.text+0x22b9): undefined reference to `glutKeyboardFunc'
transformation.c:(.text+0x22c5): undefined reference to `glutCreateMenu'
transformation.c:(.text+0x22d9): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x22ed): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x2301): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x2315): undefined reference to `glutAddMenuEntry'
transformation.c:(.text+0x2329): undefined reference to `glutAddMenuEntry'
/tmp/ccTzJ7Ag.o:transformation.c:(.text+0x233d): more undefined references to `glutAddMenuEntry' follow
/tmp/ccTzJ7Ag.o: In function `main':
transformation.c:(.text+0x2349): undefined reference to `glutAttachMenu'
transformation.c:(.text+0x2353): undefined reference to `glutMainLoop'
/tmp/ccTzJ7Ag.o:(.data+0x1b0): undefined reference to `glutBitmapTimesRoman10'
/tmp/ccpRckG7.o: In function `glmDraw(_GLMmodel*, unsigned int)':
glm.c:(.text+0x5e32): undefined reference to `glEnable'
glm.c:(.text+0x5e4a): undefined reference to `glDisable'
glm.c:(.text+0x5ea8): undefined reference to `glMaterialfv'
glm.c:(.text+0x5ec8): undefined reference to `glMaterialfv'
glm.c:(.text+0x5ee8): undefined reference to `glMaterialfv'
glm.c:(.text+0x5f08): undefined reference to `glMaterialf'
glm.c:(.text+0x5f22): undefined reference to `glColor3fv'
glm.c:(.text+0x5f2e): undefined reference to `glBegin'
glm.c:(.text+0x5f96): undefined reference to `glNormal3fv'
glm.c:(.text+0x5fc2): undefined reference to `glNormal3fv'
glm.c:(.text+0x5fe8): undefined reference to `glTexCoord2fv'
glm.c:(.text+0x6009): undefined reference to `glVertex3fv'
glm.c:(.text+0x6035): undefined reference to `glNormal3fv'
glm.c:(.text+0x605b): undefined reference to `glTexCoord2fv'
glm.c:(.text+0x607d): undefined reference to `glVertex3fv'
glm.c:(.text+0x60a9): undefined reference to `glNormal3fv'
glm.c:(.text+0x60cf): undefined reference to `glTexCoord2fv'
glm.c:(.text+0x60f1): undefined reference to `glVertex3fv'
glm.c:(.text+0x611d): undefined reference to `glEnd'
/tmp/ccpRckG7.o: In function `glmList(_GLMmodel*, unsigned int)':
glm.c:(.text+0x6150): undefined reference to `glGenLists'
glm.c:(.text+0x6166): undefined reference to `glNewList'
glm.c:(.text+0x617d): undefined reference to `glEndList'
collect2: ld returned 1 exit status

我是一只鱼
我是一只鱼
@罗光盛 : OK,我试了一下,还是没用,可能后来的几个函数最高版本里面支持。
everyx
everyx
@我是一只鱼 : 在g++中加入-L/usr/lib/ 和-lGL -lGLU试试
我是一只鱼
我是一只鱼
@罗光盛 : 这个freeglut装了,要不然也不能编译OpenGL里面大部分函数了。
everyx
everyx
找找freeglut的包安装看看
0
six
six

很明显你的源码是依赖某些库的,你确定你的程序依赖的库都安装完啦?

在VC和VS里编译通过,绝对不能说明你的代码在linux下是没有问题的。

0
six
six

另,你贴出来的错误哪有未找到头文件,分明是众多的“未能解引用”,

最后一句告诉你编译成功了,只是链接时出错啦,你试一下链接一下相关的库编译下

0
周翼翼
周翼翼

楼主,你在哪下人家的源代码吧.人家的源代码是依赖openGL的,你要链接上去.在vs下看看项目属性-链接-附加依赖项那里你就可以看到,有glut32.lib类似的东西了.如果不是,就是在源文件里有#pragma comment (lib, "glu32.lib")这种.这命令在g++下估计没用吧.

加上 -lGL -lglut

如果提示找不到libGL什么的,就是你没装opengl了,请自觉装上.

0
我是一只鱼
我是一只鱼

引用来自“周翼翼”的答案

楼主,你在哪下人家的源代码吧.人家的源代码是依赖openGL的,你要链接上去.在vs下看看项目属性-链接-附加依赖项那里你就可以看到,有glut32.lib类似的东西了.如果不是,就是在源文件里有#pragma comment (lib, "glu32.lib")这种.这命令在g++下估计没用吧.

加上 -lGL -lglut

如果提示找不到libGL什么的,就是你没装opengl了,请自觉装上.

您好,谢谢您的提醒,OpenGL已经安装了,我写个小程序是可以运行的
0
我是一只鱼
我是一只鱼

引用来自“six”的答案

另,你贴出来的错误哪有未找到头文件,分明是众多的“未能解引用”,

最后一句告诉你编译成功了,只是链接时出错啦,你试一下链接一下相关的库编译下

您算是说对了,没错。
0
我是一只鱼
我是一只鱼

引用来自“周翼翼”的答案

楼主,你在哪下人家的源代码吧.人家的源代码是依赖openGL的,你要链接上去.在vs下看看项目属性-链接-附加依赖项那里你就可以看到,有glut32.lib类似的东西了.如果不是,就是在源文件里有#pragma comment (lib, "glu32.lib")这种.这命令在g++下估计没用吧.

加上 -lGL -lglut

如果提示找不到libGL什么的,就是你没装opengl了,请自觉装上.

命令:gcc transformation.c glm.c -o transformation -lglut
出现:/tmp/ccS0szqm.o: In function `main_reshape':
transformation.c:(.text+0xc26): undefined reference to `gluOrtho2D'
/tmp/ccS0szqm.o: In function `world_reshape':
transformation.c:(.text+0xf39): undefined reference to `gluPerspective'
/tmp/ccS0szqm.o: In function `screen_reshape':
transformation.c:(.text+0x1627): undefined reference to `gluPerspective'
transformation.c:(.text+0x16bc): undefined reference to `gluLookAt'
/tmp/ccS0szqm.o: In function `command_reshape':
transformation.c:(.text+0x1921): undefined reference to `gluOrtho2D'
collect2: ld returned 1 exit status
我查看了一下gluOrtho2D,gluPerspective,gluLookAt这三个函数在某些版本是已经失效了,您知道这三个函数有现存函数代替?除了自己编写的
周翼翼
周翼翼
这个我也不知.我用opengl只用过一个函数,glDrawPixels~~
返回顶部
顶部