首页 > 解决方案 > 如何让#include<> 查看标准系统目录的子文件夹?

问题描述

我在下面发表了原始帖子,但认为这个问题可以更笼统。

我安装了一个名为 ibex 的 c++ 库。它包含一个文件 ibex.h 和一个子文件夹 ibex,该子文件夹包含更多由 ibex.h 调用的头文件。ibex.h 和子文件夹都位于 /usr/local/include 中。我已经确认这是在我的标准系统目录中。

我正在尝试从下面名为 foo.cpp 的 ibex 网站运行示例代码

#include <ibex.h>
#include <iostream>

using namespace std;
using namespace ibex;

int main(int argc, char** argv) {
  Interval x(0,1);
  cout << "My first interval:" << x << endl;
}

但得到错误

In file included from (filelocationremoved)/foo.cpp:1:
/usr/local/include/ibex.h:6:10: fatal error: 'ibex_Setting.h' file not found

所以基本上它可以找到 ibex.h 但不会在子文件夹中查找 ibex_Setting.h (或子文件夹中的任何其他文件)。有没有办法让它查看该子文件夹中的所有文件,就好像它们在 /usr/local/include 文件夹中一样,而无需将它们全部移入?

谢谢!

原帖:

我是一个新手 c++ 用户(我主要使用 Matlab 和一点 Python),但需要将 c++ 用于 ibex 库(http://www.ibex-lib.org)。我正在尝试编译他们的基本示例,但遇到了问题。我希望这里的一些有经验的用户可以提供帮助,因为我没有取得任何进展。

笔记:

我正在尝试从他们的名为 foo.cpp 的文档中运行以下示例代码

#include <ibex.h>
#include <iostream>

using namespace std;
using namespace ibex;

int main(int argc, char** argv) {
  Interval x(0,1);
  cout << "My first interval:" << x << endl;
}

但得到错误

In file included from (filelocationremoved)/foo.cpp:1:
/usr/local/include/ibex.h:6:10: fatal error: 'ibex_Setting.h' file not found

ibex_Setting.h 文件是 ibex.h 调用的众多文件之一。我有位于 /usr/local/include 的 ibex.h 文件,它似乎能够找到它。我在同一个 /usr/local/include 文件夹中还有一个 ibex 文件夹的别名(所有相关子文件所在的位置)。但它不会在该子文件夹中查找。该子文件夹是由创建的brew link ibex,我认为应该可以找到它。如果我将 ibex_Setting.h 移动到 /usr/local/include 文件夹中,它会找到它,但会移动到它找不到的下一个文件(也位于 /usr/local/include/ibex 中)。该文件夹有足够的文件,我不想手动将它们全部移动到 /usr/local/include 中。此外,需要这样做似乎很愚蠢。

在 ibex 文档中,它还说要这样做: export DYLD_LIBRARY_PATH=[prefix]/lib,其中前缀是文件夹位置。我的 libibex.dylib 位于我使用的 /usr/local/lib 中。这没有帮助。我确定我没有提供足够的信息,但我还是 C++ 新手,所以甚至不知道还包括什么。任何帮助将不胜感激!

谢谢

标签: c++header-files

解决方案


/usr/local/include 是 ibex.h 所在的位置。尝试在附加包含目录中添加 ibex_Setting.h 所在的子目录的路径路径。或者,如果您没有找到其他包含目录设置,请使用 ../../../Path 来定位您的包含文件。


推荐阅读