visual c ++:#include同一解决方案中其他项目的文件 [英] visual c++: #include files from other projects in the same solution

查看:1089
本文介绍了visual c ++:#include同一解决方案中其他项目的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual C ++开发一个游戏。我有一些组件在单独的项目中,并已设置项目依赖项。我如何#include来自不同项目的头文件?我不知道如何使用另一个项目中的类。

I am working on a game using Visual C++. I have some components in separate projects, and have set the project dependencies. How do I #include a header file from a different project? I have no idea how to use classes from one project in another.

推荐答案

编译器的设置



在要从另一个项目中包含头文件的项目中,您需要将头文件的路径添加到 Additional Include Directories 部分。

Settings for compiler

In the project where you want to #include the header file from another project, you will need to add the path of the header file into the Additional Include Directories section in the project configuration.

要访问项目配置:


  1. 右键单击项目并选择属性。

  2. 选择配置属性 - > C / C ++ - >常规。




如何添加



包含头文件,只需在代码中写下:

How to include

To include the header file, simply write the following in your code:

#include "filename.h"

请注意,您不需要在此处指定路径,因为您将目录包含在Additional Include目录中已经,所以Visual Studio将知道在哪里寻找它。

Note that you don't need to specify the path here, because you include the directory in the Additional Include Directories already, so Visual Studio will know where to look for it.

如果你不想添加每个头文件位置在项目设置,你可以只包括目录到某一点,然后#include相对于该点:

If you don't want to add every header file location in the project settings, you could just include a directory up to a point, and then #include relative to that point:

// In project settings
Additional Include Directories    ..\..\libroot

// In code
#include "lib1/lib1.h"    // path is relative to libroot
#include "lib2/lib2.h"    // path is relative to libroot



链接器设置



如果使用静态库(即.lib文件),您还需要将链接器输入中添加库,以便在链接时可以链接符号(否则会得到未解决的符号):

Setting for linker

If using static libraries (i.e. .lib file), you will also need to add the library to the linker input, so that at linkage time the symbols can be linked against (otherwise you'll get an unresolved symbol):


  1. 右键单击项目,然后选择属性。

  2. 选择配置属性 - >链接器 - >输入

  3. 在其他依赖关系下输入库。

这篇关于visual c ++:#include同一解决方案中其他项目的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆