修复LNK2019:无法解决的外部符号与freeglut
Fix LNK2019: unresolved external symbol with freeglut
使用本手册,我试图在我的计算机上编译免费的OpenGL应用程序。这意味着I:
- 从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++代码来自这里。所有函数都可以在freeglut头文件中找到。
这似乎是一个C vs C++
链接问题。您正在从那里编译C source
代码作为C++ code
(也许您将其保存为c++特定的扩展并且编译器假设它是c++)。
c++会混淆函数名。例如,__imp__glutMainLoop@0
很可能是源代码中对glutMainLoop
的调用。
库必须来自C代码。因此,它将有一个简单的glutMainLoop
版本的函数。这就是为什么找不到它的原因。
解决方案是将代码编译为C代码或使用外部"C"。
编辑:一些关于如何处理C/c++链接问题的链接(从注释中移出)。
- http://www.thegeekstuff.com/2013/01/mix-c-and-cpp/ 结合c++和C -如何#ifdef __cplusplus工作?
- http://www.parashift.com/c + + -faq-lite/c-calls-cpp.html
相关文章:
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector