如何在其他src文件夹中包含头文件 [英] how to include header files in other src folder

查看:41
本文介绍了如何在其他src文件夹中包含头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个src文件夹的c ++项目.文件夹1中的源文件可能需要在src文件夹2中包含头文件.可能吗?还是应该如何编写我的Makefile?谢谢

I have a c++ project having two src folders. Source file in folder 1 may need to include header file in src folder 2. Is it possible? or how should I write my Makefiles? thanks

推荐答案

取决于这两个文件夹之间的关联程度(例如,如果它们是同一项目),那么它可以很简单:

Depending on how closely the two folders are related (eg, if they're the same project), then it can be as easy as:

#include "../otherfolder/header.h"

如果它们是单独的项目,则习惯上只需将另一个项目的标头目录添加到项目的标头搜索路径中,并包括如下标头:

If they're separate projects, then it's customary to simply add the other project's header directory to your project's header search path, and include the header like this:

#include <header.h>

(实际上,方括号/引号无关紧要,但这有助于使外部和内部标头导入保持分开)

(In practice, the brackets/quotes don't matter, but it helps keep external vs. internal header imports separate)

这篇关于如何在其他src文件夹中包含头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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