视觉C 错误LNK2019
Visual C++ error LNK2019
好吧,所以我一直使用gcc
编译器。这是我与这个IDE的第一个项目。我的项目是这样组织的:
main.cpp
包括 a.h
a.c
包括a.h
并实现a.h
中声明的方法
当我编译时,我会得到以下内容:
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl destroyPlayer(struct player *)" (?destroyPlayer@@YAXPAUplayer@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl drawPlayer(struct player *)" (?drawPlayer@@YAXPAUplayer@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl movePlayer(struct player *,int *)" (?movePlayer@@YAXPAUplayer@@PAH@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "struct player * __cdecl createPlayer(int,int)" (?createPlayer@@YAPAUplayer@@HH@Z) referenced in function _main
这些都是a.h
中的所有功能。使用GCC命令行,我可以将它们编译在一起。所有文件都添加到项目中。我想念什么吗?
错误消息是自称的:
未解决的外部符号" void __ cdecl destroyplayer ...
您有main.cpp和a.c。
对于main.cpp链接器期望在a.h中声明的所有功能使用C 名称mangling和C 调用惯例,而对于A.C链接器,请期望在A.H中声明的所有功能使用C naming和__cdecl调用convention。
如果您的A.C中的代码不使用C 功能,并且您想从Main.CPP调用它,它确实使用C 功能,那么在A.H中,您需要添加以下内容:
#ifdef __cplusplus
extern "C" {
#endif
// your function declarations
#ifdef __cplusplus
}
#endif
另外,如果您不需要混合C和C ,请将所有文件重命名为.c或.cpp。
最后,确保文件实际上是重命名的,因为Visual Studio支持"虚拟"重命名(仅在项目中,而无需重命名实际文件)。
我相信Visual Studio会自动编译.c
文件作为C文件,因此名称Mangling可以在此中发挥作用。尝试将a.c
重命名为a.cpp
,看看是否有帮助。
相关文章:
- 链接CPP文件进行测试时发生LNK2019错误
- 32位到64位:LNK2019错误,如何检索相关信息
- 在结构函数之间传递文件路径 C++ 编辑:修复LNK2019错误
- 尝试使用 TMXlite 编译项目时LNK2019错误
- LNK2019错误;此处缺少/未定义的内容
- DX11 DirectInput8创建引起LNK2019错误
- C++ mysql 仅在构建解决方案时LNK2019错误
- C LNK2019错误,未解决的外部字符
- C++ 带有出现LNK2019错误的对象的链接列表
- 解决 main 中的LNK2019错误
- 尝试使用命名空间中的函数时LNK2019错误
- LNK2019错误未解析的外部符号
- LNK2019错误,在Visual Studio 2012 C++的main中使用的函数
- 同一项目中两个类之间的visual c++LNK2019错误
- LNK2019错误(未解析的外部符号)将SQLite链接到DLL
- C++/CLI 包装器LNK2028和LNK2019错误
- LNK2019错误,尝试覆盖运算符<< 对于 LinkedList 类
- LNK2001和LNK2019错误 - DirectX 未解析的外部符号
- (2012)Visual C++LNK2019错误,可能是模板问题
- LNK2019错误一个DLL链接到MFC DLL