在Visual studio-LNK2001中的同一解决方案中包含来自单独项目的文件
Including files from a seperate project in the same solution in Visual studio - LNK2001?
我有一个名为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.
ps。我没有观察到,但在错误消息中,您可以看到函数正在等待一个参数。这样称呼它:
unsigned long foo = 0;
candy::get(foo);
这听起来很愚蠢,但。。。我只是把文件拖到visualstudio中,这样no.morefun项目的"目录"中也有"文件"。
哇。。。我不应该那样做。。。我错了吗?(讽刺)。
相关文章:
- 用C++在单独的头文件中完成函数体
- 如何使用单独文件中的派生类访问友元函数对象
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- 如何将 2 个类分成单独的 .h 文件并正确设置它们
- 单独文件中各种 c++ 类的标头出现问题
- 如何在单独文件中定义的成员函数中使用成员变量
- 试图将两个类放在同一命名空间中的单独文件中,但只有#1个#Class类作品
- 包括arduino中单独文件中的函数
- 视觉对象包括 C++ 中单独文件夹中的文件
- C 向量排序 .h .cpp中的单独文件
- 与构造函数、类和单独文件混淆
- GST_DEBUG:如何将日志保存在应用程序内线程的单独文件中
- 类在单独文件中的奇怪行为
- 单独文件中的C++内部模板类
- 从单独文件(C++)中的用户输入数据创建矢量
- 将函数添加到单独文件的正确方式
- C++:链接器错误:未定义的引用仅指向在单独文件中定义的一个特定类成员
- 实例化单独文件中的类
- 将对象文件放入GNU make的单独文件夹中
- 如何初始化对在单独文件中声明的类的引用