我正在使用Ubuntu,并尝试使用Synaptic安装所有包含“GLUT”以及SDL和OpenGL的软件。但是一个简单的程序仍然无法编译。它显示以下错误:
opengl1.cpp:(.text+0xe): 无法找到对 `glClear' 的引用 opengl1.cpp:(.text+0x1a): 无法找到对 `glBegin' 的引用 opengl1.cpp:(.text+0x2e): 无法找到对 `glVertex2i' 的引用 opengl1.cpp:(.text+0x33): 无法找到对 `glEnd' 的引用 opengl1.cpp:(.text+0x38): 无法找到对 `glFlush' 的引用 /tmp/ccnwQeLu.o: 在函数 `MyInit()': opengl1.cpp:(.text+0x4c): 无法找到对 `glGetString' 的引用 opengl1.cpp:(.text+0x57): 无法找到对 `std::cout' 的引用 opengl1.cpp:(.text+0x5c): 无法找到对 `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)' 的引用 opengl1.cpp:(.text+0x6c): 无法找到对 `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)' 的引用 opengl1.cpp:(.text+0x78): 无法找到对 `glGetString' 的引用 opengl1.cpp:(.text+0x83): 无法找到对 `std::cout' 的引用 opengl1.cpp:(.text+0x88): 无法找到对 `std::basic_ostream >& std::operator >(std::basic_ostream >&, unsigned char const*)' 的引用 opengl1.cpp:(.text+0x98): 无法找到对 `std::basic_ostream >& std::operator >(std::basic_ostream >&, char const*)' 的引用 opengl1.cpp:(.text+0xc0): 无法找到对 `glClearColor' 的引用 opengl1.cpp:(.text+0xdf): 无法找到对 `glColor3f' 的引用 opengl1.cpp:(.text+0xec): 无法找到对 `glPointSize' 的引用 opengl1.cpp:(.text+0xf8): 无法找到对 `glMatrixMode' 的引用 opengl1.cpp:(.text+0xfd): 无法找到对 `glLoadIdentity' 的引用 opengl1.cpp:(.text+0x12d): 无法找到对 `gluOrtho2D' 的引用 /tmp/ccnwQeLu.o: 在函数 `main': opengl1.cpp:(.text+0x14a): 无法找到对 `glutInit' 的引用 opengl1.cpp:(.text+0x156): 无法找到对 `glutInitDisplayMode' 的引用 opengl1.cpp:(.text+0x16d): 无法找到对 `glutInitWindowSize' 的引用 opengl1.cpp:(.text+0x181): 无法找到对 `glutInitWindowPosition' 的引用 opengl1.cpp:(.text+0x18d): 无法找到对 `glutCreateWindow' 的引用 opengl1.cpp:(.text+0x19e): 无法找到对 `glutDisplayFunc' 的引用 opengl1.cpp:(.text+0x1a3): 无法找到对 `glutMainLoop' 的引用 /tmp/ccnwQeLu.o: 在函数 `__static_initialization_and_destruction_0(int, int)': opengl1.cpp:(.text+0x1cb): 无法找到对 `std::ios_base::Init::Init()' 的引用 opengl1.cpp:(.text+0x1d0): 无法找到对 `std::ios_base::Init::~Init()' 的引用 /tmp/ccnwQeLu.o:(.eh_frame+0x12): 无法找到对 `__gxx_personality_v0' 的引用 collect2: ld 返回 1 退出状态如果我使用g ++而不是gcc,我会得到这个:
vim opebgl1.cpp g ++ opengl1.cpp -o opengl1 -lGL -lstdc ++ -lc -lm 然后得到这个: /tmp/ccCJBuIl.o:在函数“MyInit()”中: opengl1.cpp:(.text + 0x12d):对“gluOrtho2D”的未定义引用 /tmp/ccCJBuIl.o:在函数“main”中: opengl1.cpp:(.text + 0x14a):对“glutInit”的未定义引用 opengl1.cpp:(.text + 0x156):对“glutInitDisplayMode”的未定义引用 opengl1.cpp:(.text + 0x16d):对“glutInitWindowSize”的未定义引用 opengl1.cpp:(.text + 0x181):对“glutInitWindowPosition”的未定义引用 opengl1.cpp:(.text + 0x18d):对“glutCreateWindow”的未定义引用 opengl1.cpp:(.text + 0x19e):对“glutDisplayFunc”的未定义引用 opengl1.cpp:(.text + 0x1a3):对“glutMainLoop”的未定义引用 collect2:ld返回1个退出状态那么,在Ubuntu中真正需要开始使用OpenGL的是什么?
g++
还是gcc
进行构建? - Troubadourg++
来编译 C++ 源代码。这样你会发现与std::cout
相关的错误消失了。g++
实际上只是一个围绕着gcc
的包装器,可以自动为您链接标准的 C++ 库。如果您使用gcc
,则必须手动链接。使用g++
更加简单方便。 - Troubadour