Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ visualc&x2B+;错误LNK2019_C++_C_Visual Studio 2010 - Fatal编程技术网

C++ visualc&x2B+;错误LNK2019

C++ visualc&x2B+;错误LNK2019,c++,c,visual-studio-2010,C++,C,Visual Studio 2010,好的,所以我一直使用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 func

好的,所以我一直使用
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命令行,我可以将它们编译在一起。所有文件都将添加到项目中。我遗漏了什么吗?

我相信Visual Studio会自动将
.c
文件编译为c文件,因此名称混乱可能是其中的一部分。尝试将
a.c
重命名为
a.cpp
,看看是否有帮助。

错误消息不言自明:

未解析的外部符号“void\uu cdecl销毁播放器

你有main.cpp和a.c

对于M.CPP链接器,期望在.h中声明的所有函数都使用C++名称的Mangle和C++调用约定,而对于A.C.Link则期望在A.H中声明的所有函数都使用C命名和“Y-CDCL调用约定”。

如果你的代码在Ac中不使用C++特性,并且你想从使用C++特性的Me..cp调用它,那么在A.H中你需要添加以下内容:

#ifdef __cplusplus
extern "C" {
#endif

// your function declarations

#ifdef __cplusplus
}
#endif

可选地,如果不需要混合C和C++,将所有文件重命名为.c或.cpp.< /p>


最后,确保确实重命名了文件,因为Visual Studio支持“虚拟”重命名(仅在项目中,不重命名实际文件).

named main和a to.cpp..没有帮助。那么,我是否正确地假设,一旦将文件添加到项目中,编译器会自动将其包含在编译过程中?又称gcc main.c a.c-o whatever..或者它是否尝试提取一些dll格式的东西?@Rambat是的,将其添加到项目中会使其编译。这可能是不同的。你知道吗可以转到项目属性并查看用于编译的确切命令。@Rambat尝试将故意错误放入a.c,只是为了检查它是否真的正在编译。尝试添加错误。它没有编译错误C2143:语法错误:缺少“;”before“}”。这证明a.c正在编译。这是一个真正的链接器问题。。@Luchian Grigore为noob的问题道歉..我在项目属性中的哪里可以获得确切的命令。。