如何在其他src文件夹中包含头文件

编程入门 行业动态 更新时间:2024-10-19 12:34:45
本文介绍了如何在其他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文件夹中包含头文件

本文发布于:2023-11-10 16:11:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575847.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:头文件   文件   夹中   如何在   src

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!