使用this manual,我试图在我的计算机上编译freeglut OpenGL应用程序。这意味着我:
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头文件中找到。只是缺少图书馆。
答案 0 :(得分:1)
这似乎是C vs C++
链接问题。您正在将C source
代码从there编译为C++ code
(也许您使用C ++特定的扩展保存它,并且编译器假定它是C ++)。
C ++会破坏函数名称。例如,__imp__glutMainLoop@0
最有可能在您的源代码中调用glutMainLoop
。
库必须来自C代码。因此,它将函数的非破坏版本简化为glutMainLoop
。这就是为什么找不到它。
解决方案是将代码编译为C代码或使用extern "C"。
编辑:关于如何处理C / C ++链接问题的一些链接(从评论中移出)。