VS2010如何将.h连接到项目目录的.cpp OUTSIDE

时间:2014-10-17 01:41:33

标签: c++ visual-studio-2010

这应该很简单,但我失去了睡眠:(

我有几个分为.h和.cpp的类,我将它们放在项目之外的一个单独的“classes”文件夹中,以便多个项目可以访问它们。

在项目属性下 - > VC ++目录 我用'classes'文件夹的完整路径更改了'include directories'参数。

我的类中的.h似乎在项目中可用,但我的.cpp没有正确链接,因为它们在编译时导致“错误LNK2019:未解析的外部符号”问题。我在类似的论坛帖子中找不到关于链接问题的解决方案......

//this is how the .cpp starts
//is the path wrong ? Am I missing a VS2010 setting somewhere ?
//I've tried several alternatives including full path name, brackets..
#include "CMyClass.h" 

我的目录在“.. \ Visual Studio 2010 \ Projects \”

下看起来像这样
project_one //wants to use a class from the 'classes' folder
project_two //also wants to use a class from the 'classes' folder
classes //.h and .cpp are in here 

这些类已在自己的控制台中进行了测试,因此定义肯定存在。这些类位于与项目分开的新目录中。

如何让他们找到他们的.cpp?

1 个答案:

答案 0 :(得分:2)

对于每个项目,右键单击它并选择“添加现有项目...”并选择您的共享CPP文件。必须将每个CPP文件添加到使用它的每个项目中。这不会复制磁盘上的CPP文件,如果它们位于磁盘上的项目目录之外也无关紧要。