c++ - 在 C++ 中使用 #include 包含多个

标签 c++ c++11 include

我对 C++ 中的 #include 预处理器指令有疑问。

在我的程序中,我想包含来自另一个目录的头文件。为此,我使用了完整路径,例如:

#include "full/path/to/my/header.hpp"

现在发现 header.hpp 本身有一个 include(比方说 #include "otherheader.hpp"。在编译过程中,编译器提示找不到这个其他标题。

考虑到我也不想写每个头文件的完整路径,尤其是包括那些只需要“在树下”的头文件,处理这个问题的最佳方法是什么?

最佳答案

您应该使用编译器的 -I 选项。

g++ 示例:

g++ -I full/path/to/my/

然后在您的代码中您可以简单地输入:

#include "header.hpp"

More information on search path.

关于c++ - 在 C++ 中使用 #include 包含多个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49135951/

相关文章:

c++ - 正确使用c++中的Matlab "engine.h"

c++ - 如何仅使用标准库编写 XML 解析器?

c++ - vc++中如何获取windows时间?

c++ - 需要一些关于 r 值概念的帮助

php - 为什么 PHP 会在本地包含的函数中抛出 "Cannot Redeclare"错误?

c++ - 如何不#include <windows.h>

c++ - 使用 QTCreator 自动生成 setter / getter ?

c++ - 在 C++ 中重载 setter/getter ?

c++ - 为什么 `std::unordered_map` "speak like the Yoda"- 重新排列元素?

xcode - 如何使用 pkg-config 在 Xcode 中设置包含路径?