OpenGL / glut / stdc ++构建错误 [英] OpenGL/glut/stdc++ build errors

查看:289
本文介绍了OpenGL / glut / stdc ++构建错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Ubuntu并尝试使用synaptic安装所有的GLUT一词,还有SDL和opengl。但是一个简单的程序仍然无法编译。它显示:

I'm using Ubuntu and tried using synaptic to install everything that had the word "GLUT" in it and also SDL and opengl . But still a simple program fails to compile . It shows this :


opengl1.cpp:(.text+0xe): undefined reference to `glClear'
opengl1.cpp:(.text+0x1a): undefined reference to `glBegin'
opengl1.cpp:(.text+0x2e): undefined reference to `glVertex2i'
opengl1.cpp:(.text+0x33): undefined reference to `glEnd'
opengl1.cpp:(.text+0x38): undefined reference to `glFlush'
/tmp/ccnwQeLu.o: In function `MyInit()':
opengl1.cpp:(.text+0x4c): undefined reference to `glGetString'
opengl1.cpp:(.text+0x57): undefined reference to `std::cout'
opengl1.cpp:(.text+0x5c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)'
opengl1.cpp:(.text+0x6c): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)'
opengl1.cpp:(.text+0x78): undefined reference to `glGetString'
opengl1.cpp:(.text+0x83): undefined reference to `std::cout'
opengl1.cpp:(.text+0x88): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)'
opengl1.cpp:(.text+0x98): undefined reference to `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)'
opengl1.cpp:(.text+0xc0): undefined reference to `glClearColor'
opengl1.cpp:(.text+0xdf): undefined reference to `glColor3f'
opengl1.cpp:(.text+0xec): undefined reference to `glPointSize'
opengl1.cpp:(.text+0xf8): undefined reference to `glMatrixMode'
opengl1.cpp:(.text+0xfd): undefined reference to `glLoadIdentity'
opengl1.cpp:(.text+0x12d): undefined reference to `gluOrtho2D'
/tmp/ccnwQeLu.o: In function `main':
opengl1.cpp:(.text+0x14a): undefined reference to `glutInit'
opengl1.cpp:(.text+0x156): undefined reference to `glutInitDisplayMode'
opengl1.cpp:(.text+0x16d): undefined reference to `glutInitWindowSize'
opengl1.cpp:(.text+0x181): undefined reference to `glutInitWindowPosition'
opengl1.cpp:(.text+0x18d): undefined reference to `glutCreateWindow'
opengl1.cpp:(.text+0x19e): undefined reference to `glutDisplayFunc'
opengl1.cpp:(.text+0x1a3): undefined reference to `glutMainLoop'
/tmp/ccnwQeLu.o: In function `__static_initialization_and_destruction_0(int, int)':
opengl1.cpp:(.text+0x1cb): undefined reference to `std::ios_base::Init::Init()'
opengl1.cpp:(.text+0x1d0): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccnwQeLu.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status



如果我使用g ++代替gcc我得到这个:

If I use g++ instead of gcc I get this:


vim opebgl1.cpp
g++ opengl1.cpp -o opengl1 -lGL -lstdc++ -lc -lm
 and then get this :
/tmp/ccCJBuIl.o: In function `MyInit()':
opengl1.cpp:(.text+0x12d): undefined reference to `gluOrtho2D'
/tmp/ccCJBuIl.o: In function `main':
opengl1.cpp:(.text+0x14a): undefined reference to `glutInit'
opengl1.cpp:(.text+0x156): undefined reference to `glutInitDisplayMode'
opengl1.cpp:(.text+0x16d): undefined reference to `glutInitWindowSize'
opengl1.cpp:(.text+0x181): undefined reference to `glutInitWindowPosition'
opengl1.cpp:(.text+0x18d): undefined reference to `glutCreateWindow'
opengl1.cpp:(.text+0x19e): undefined reference to `glutDisplayFunc'
opengl1.cpp:(.text+0x1a3): undefined reference to `glutMainLoop'
collect2: ld returned 1 exit status

真的需要开始在Ubuntu中使用opengl吗?

So what do I really need to start working with opengl in Ubuntu?

推荐答案

将-lstdc ++ -lGL添加到链接器标记。
或者尝试这样编译:

Add "-lstdc++ -lGL" to your linker flags. Or try to compile it like this:

g++ opengl1.cpp -o opengl1 -lGL -lGLU -lc -lm

(编辑:已添加-lGLU,已删除-lstdc ++)

(edit: added -lGLU, removed -lstdc++)

这篇关于OpenGL / glut / stdc ++构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆