gpt4 book ai didi

c++ - OpenGL/glut/stdc++ 构建错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:15:03 33 4
gpt4 key购买 nike

我正在使用 Ubuntu 并尝试使用 synaptic 来安装其中包含“GLUT”一词的所有内容以及 SDL 和 opengl 。但仍然是一个简单的程序无法编译。它显示了这个:

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,我会得到这个:

vim opebgl1.cppg++ 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 我真正需要什么?

最佳答案

将“-lstdc++ -lGL”添加到您的链接器标志。或者尝试像这样编译它:

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

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

关于c++ - OpenGL/glut/stdc++ 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410832/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com