Eclipse for C++ 无法识别酿造的 GSL 和 Boost 库

Eclipse for C++ not recognizing brewed GSL and Boost libraries

我在系统 运行 Mac OS X 上。我正在使用 Eclipse Oxygen.2 for C/C++,在我的例子中是 C++。我正在尝试创建一个使用 GSL 和 Boost 库的项目。但是,Eclipse 似乎无法找到 GSL 库,似乎可以识别 Boost 库,但似乎无法执行 Boost 库中包含的任何操作。这两个库都是使用 Homebrew 安装的。这是我正在使用的代码:

#include <iostream>
#include <gsl.h>
#include <boost/optional.hpp>
using namespace std;

int main () {
    int x = 5;
    gsl::owner<int*> p = &x;
    boost::optional<string>;
    return 0;
}

报错如下:

  1. 用行#include <gsl.h>表示fatal error: 'gsl.h' file not found.

  2. gsl::owner<int*> p = &x; 显示 Symbol 'owner' could not be resolved

  3. boost::optional<string>; 行显示 Type 'boost::optional<string>' could not be resolved。这个很奇怪,因为 boost/optional.hpp 文件似乎没有问题。

其他信息可能会有帮助:

我正在使用 MacOS X 工具链。我应该切换到 Cross GCC 工具链吗?

这是项目首选项下列出的库搜索路径 > C/C++ 构建 > 设置 > MacOS X C++ 链接器 > 库:/usr/local/Cellar/boost/1.66.0/include/usr/local/Cellar/gsl/2.4/include.

我正在关注 Trevor Payne 的 Let's Learn C++ 教程系列。

看起来您在 header 文件中指出了库,而不是包含。

右键单击项目资源管理器中的保护。 Select pop-up 菜单中的属性。在属性对话框 C/C++ General->Paths And Symbols 中导航。 Select 包含选项卡。将 /usr/local/Cellar/boost/1.66.0/include 和 /usr/local/Cellar/gsl/2.4/include 添加到所有配置的 C++ 语言中。

从“库”选项卡中删除包含目录,然后前往“库路径”选项卡添加库的位置(如果需要)。 Boost 通常只有 header。 GSL 我不知道 Atom。

找出正确的问题并提供良好的调试信息,做得很好。

既然你已经用 Homebrew 安装了 GSL 和 Boost,它们可能安装正确,编译器只是找不到正确的 header 和库文件 --这可能是因为您在错误的设置中使用了错误的路径。

Linker > Libraries 选项中,您为 Boost 和 GSL 使用了两个 include 路径。这些属于用于查找 header 的不同路径选项,而不是库(我不确定它的确切位置,我没有 mac!)。确保您在此处仔细按照教程的说明进行操作。

还需要将库路径放入库选项中,但是:例如: /usr/local/Cellar/gsl/2.4/include 应该类似于 /usr/local/Cellar/gsl/2.4/lib