Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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++ 在VisualStudio-LNK2001的同一解决方案中包含来自单独项目的文件?_C++_Visual Studio - Fatal编程技术网

C++ 在VisualStudio-LNK2001的同一解决方案中包含来自单独项目的文件?

C++ 在VisualStudio-LNK2001的同一解决方案中包含来自单独项目的文件?,c++,visual-studio,C++,Visual Studio,我有一个名为fun.sln的解决方案和一个名为fun.vcxproj的项目 我创建了一大堆可供使用的名称空间 我做了另一个项目叫no_more_fun.vcxproj 我将fun.vcxproj的includes目录添加到no_more_fun.vcxproj的配置中 我将此添加到no_more_fun.cpp #include "candy.h" void main(void) { candy::get(); return; } candy.h位于fun.vcxproj(已添加到配置中

我有一个名为fun.sln的解决方案和一个名为fun.vcxproj的项目

我创建了一大堆可供使用的名称空间

我做了另一个项目叫no_more_fun.vcxproj

我将fun.vcxproj的includes目录添加到no_more_fun.vcxproj的配置中

我将此添加到no_more_fun.cpp

#include "candy.h"

void main(void)
{

candy::get();
return;

}
candy.h位于fun.vcxproj(已添加到配置中)的默认目录中

但是我得到

LNK2001 unresolved external symbol "int __cdecl candy::get(unsigned long)" (?get@candy@@YAHK@Z) .....
Visual Studio在编译之前不会显示任何错误

“candy”命名空间在“fun”项目中运行良好,因此idn


是否有一个指南或其他东西可以让我了解如何在一个解决方案中的不同项目之间高效地共享代码?

这是一个链接器错误。您在编译时没有得到任何错误,因为编译器在candy.h头中找到了candy::get()方法,但是链接器找不到实现(我想是在candy.cpp文件中)。 只需将candy.cpp也添加到no_more_fun.vcxproj

另外,我没有观察到,但是在错误消息中,您可以看到函数等待一个参数。 可以这样称呼:

unsigned long foo = 0;
candy::get(foo);

这听起来很愚蠢,但是…我只是把文件拖到了VisualStudio中,这样“无更多乐趣”项目的“目录”中也有“文件”

哇。。。我不需要那样做……我错了吗?(讽刺)。

可能是重复的