Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何获得#包含<&燃气轮机;要查找标准系统目录的子文件夹?_C++_Header Files - Fatal编程技术网

C++ 如何获得#包含<&燃气轮机;要查找标准系统目录的子文件夹?

C++ 如何获得#包含<&燃气轮机;要查找标准系统目录的子文件夹?,c++,header-files,C++,Header Files,我发表了下面的原始帖子,但我认为这个问题可以更一般化 < >我安装了一个叫做iBEX的C++库。它包含一个文件ibex.h和一个子文件夹ibex,子文件夹包含更多由ibex.h调用的头文件。ibex.h和子文件夹都位于/usr/local/include中。我已经确认这是在我的标准系统目录 我试图运行下面ibex网站foo.cpp中的示例代码 #include <ibex.h> #include <iostream> using namespace std; using

我发表了下面的原始帖子,但我认为这个问题可以更一般化

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

我试图运行下面ibex网站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;
}
#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;
}
因此,它基本上可以找到ibex.h,但不会在子文件夹中查找ibex_Setting.h(或子文件夹中的任何其他文件)。有没有一种方法可以让它查看该子文件夹中的所有文件,就好像它们在/usr/local/include文件夹中一样,而不将它们全部移入

谢谢

原职:

<>我是新手C++用户(我主要使用MATLAB和一个小Python),但是需要用C++来做IPEX库()。我试图编译他们的基本示例,但遇到了一些问题。我希望这里的一些有经验的用户能够帮助我,因为我没有取得任何进展

注:

  • 运行MacOS Catalina
  • 为我的IDE使用升华文本
  • 我已经安装了Xcode,可以运行hello world示例
  • 已安装的ibex使用:
    brew安装ibex
我试图从他们名为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;
}
#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;
}
ibex_Setting.h文件是ibex.h调用的众多文件之一。我的ibex.h文件位于/usr/local/include中,它似乎能够找到它。我在同一个/usr/local/include文件夹中还有一个ibex文件夹的别名(所有相关子文件都位于该文件夹中)。但它不会在该子文件夹中查找。该子文件夹是由
brew link ibex
创建的,我认为它应该是可查找的。如果我将ibex_Setting.h移动到/usr/local/include文件夹中,它会找到它,但会移动到下一个找不到的文件(也位于/usr/local/include/ibex中)。文件夹中有足够的文件,我不想手动将它们全部移动到/usr/local/include。而且,这样做似乎很愚蠢

在ibex文档中,它还表示要执行以下操作:
export DYLD\u LIBRARY\u PATH=[prefix]/lib
,其中prefix是文件夹位置。我的libibex.dylib位于我使用的/usr/local/lib中。这没有帮助。我确信我没有提供足够的信息,但是我对C++也是新的,所以甚至不知道还有什么要包括。任何帮助都将不胜感激


谢谢

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

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

我不喜欢XCode和升华文本,但我可以向您展示一个演示 以及如何在编译器级别解决该问题。你怎么能工作 在IDE的编译器设置中应用

以下是程序的项目文件夹的内容:

$ ls -R
.:
header.h  main.cpp  subfolder

./subfolder:
subheader.h
以下是源文件和标题:

$ cat main.cpp
#include <header.h>

int main()
{
    return foo();
}

$ cat header.h
#ifndef HEADER_H
#define HEADER_H

#include <subheader.h>

inline int foo() {
    return bar();
}

#endif

$ cat subfolder/subheader.h 
#ifndef SUBHEADER_H
#define SUBHEADER_H

inline int bar() {
    return 42;
}

#endif
这不起作用,因为预处理器不知道在哪里查找 对于系统标题
。(在此上下文中,系统标题仅为 是指
中指定的头文件,与本地头文件相反, 将在
“…”
中指定,并将在当前 编译器运行时的目录)

我可以通过添加一个
-I dir
预处理器选项来解决这个问题,该选项告诉预处理器 在目录
dir
中搜索头文件。因为
header.h
在当前 在这个演示中,我将只使用
作为目录名,而不是 键入完整的目录名

$ g++ -Wall -I. -o prog main.cpp
In file included from main.cpp:1:
./header.h:4:10: fatal error: subheader.h: No such file or directory
    4 | #include <subheader.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
现在一切都好了

因此,首先,您需要做的是在IDE项目中进行设置,以指定 将
-I/usr/local/include
-I/usr/local/include/subfolder
传递给 编译命令。但事实上,您不需要第一个,因为
/usr/local/include
始终是头文件的默认编译器搜索目录。答案 也许对你有帮助,尽管它很旧

是否有类似于
-I dir
的选项可以使预处理器递归搜索 在
dir
的子文件夹中解析
#是否包含
指令?不,没有

请注意,如果我用以下代码编码
header.h

#include <subfolder/subheader.h>
#包括
而不是:

#include <subheader.h>
#包括
然后我可以在第二次尝试时编译我的程序,
g++-Wall-I.-oprogmain.cpp

组织良好的软件包倾向于使用 允许成功编译的必要路径元素,如
最多有一个
-I base/path
选项,其中
base/path
是 所有的
#都包括
指令。但有些包裹没有,而且在那里

这可能是一个很好的理由。

我不喜欢XCode和Sublime文本,但我可以给你演示一下 以及如何在编译器级别解决该问题。你怎么能工作 在IDE的编译器设置中应用

以下是程序的项目文件夹的内容:

$ ls -R
.:
header.h  main.cpp  subfolder

./subfolder:
subheader.h
以下是源文件和标题:

$ cat main.cpp
#include <header.h>

int main()
{
    return foo();
}

$ cat header.h
#ifndef HEADER_H
#define HEADER_H

#include <subheader.h>

inline int foo() {
    return bar();
}

#endif

$ cat subfolder/subheader.h 
#ifndef SUBHEADER_H
#define SUBHEADER_H

inline int bar() {
    return 42;
}

#endif
这不起作用,因为预处理器不知道在哪里查找 对于系统标题
。(在此上下文中,系统标题仅为 是指
中指定的头文件,与本地头文件相反, 这将在
“…”和wo中指定