使用 this manual ,我试图让 freeglut OpenGL 应用程序在我的电脑上编译。这意味着我:
- 将文件从 freeglut 存档复制到 MS 程序文件夹
- 在附加依赖项中指定了
freeglut.lib
- 在库文件夹中明确设置 freeglut.lib 路径
但全部无效。 C++ 头文件是正确的,但库不是 - 所以我得到这些错误:
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function _wmain
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp__glutSpecialFunc@4 referenced in function _wmain
1>OpenglTest.obj : error LNK2019: unresolved external symbol "void __cdecl specialKeys(int,int,int)" (?specialKeys@@YAXHHH@Z) referenced in function _wmain
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function _wmain
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp__glutInitDisplayMode@4 referenced in function _wmain
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4
1>OpenglTest.obj : error LNK2019: unresolved external symbol __imp__glutSwapBuffers@0 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
所以我的问题:
- 你能猜出哪里出了问题吗? (不容易,但我显然找不到)
- 有没有其他谷歌手册没有找到,但比我用的好?
- 我应该下载其他存档吗?
我的 C++ 代码来了 from here .所有函数都可以在 freeglut 头文件中找到。只是缺少库。
最佳答案
这似乎是一个 C vs C++
链接问题。您正在编译来自 there 的 C 源代码
代码作为 C++ 代码
(也许您使用特定于 C++ 的扩展 保存了它,而编译器假定它是 C++)。
C++ 会破坏函数名。例如,__imp__glutMainLoop@0
很可能是对源代码中的 glutMainLoop
的调用。
库必须来自 C 代码。因此它将有一个简单的函数的非破坏版本,如 glutMainLoop
。这就是找不到它的原因。
解决方案是将您的代码编译为 C 代码或使用 extern "C" .
编辑:关于如何处理 C/C++ 链接问题的一些链接(从评论中移出)。
关于c++ - 修复 LNK2019 : unresolved external symbol with freeglut,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15722540/