将 Boost 库添加到 OS X Eclipse 中的 C++ 项目

2024-01-07

我一直在尝试使用 eclipse 使用 boost 文件系统库来设置 C++ 项目。我跟着these http://www.technoboria.com/2009/07/simple-guide-to-installing-boost-on-mac-os-x/在我的系统上安装 boost 的说明。方向差不多

  1. 下载
  2. extract
  3. 运行 bootstrap.sh
  4. 运行 ./bjam Architecture=combined

看起来一切顺利,没有错误。然后我启动 eclipse 并创建一个名为 test 的新测试项目,其中包含一个名为 test.cpp 的文件。里面的代码是:

#include <stdio.h>
#include <boost/filesystem.hpp>

int main() {
    boost::filesystem::path path("/Users/schoen"); // random pathname
    bool result = boost::filesystem::is_directory(path);
    printf("Path is a directory : %d\n", result);
    return 0;
}

这只是确保所有设置正确的简单操作。当然,我此时尝试编译但失败了。做了一些谷歌搜索并发现this http://www.ferdychristant.com/blog//archive/DOMM-76JN6N地点。它说通过转到项目属性并添加“boost_filesystem”将 boost 库添加到链接器中。我尝试了这个,但没有成功。

有人能给我指出正确的方向或者给我一些关于如何在 Eclipse 项目中设置 Boost 的提示吗?

我是 C++ 和 Eclipse 的新手,我的大部分经验是使用 Java 和 Netbeans。所以我现在很迷茫。

UPDATE

我只是想根据给出的答案更新我所尝试的内容。

根据 Alex 的建议,我将 boost_system 和 boost_filesystem 添加到链接器列表中。我仍然遇到相同的编译器错误。

根据 rve 的建议,我将 boost 库的路径添加到库搜索路径中。当这不起作用时。我清除了链接器列表,并仅使用库搜索路径进行了尝试。这也行不通。

然后我清除了图书馆搜索路径。然后,我将链接器窗口上的命令手动编辑为“g++ -L/Users/jacobschoen/Library/boost_1_45_0/stage/lib -lboost -lboost_filesystem”。这也行不通。

在所有这些中,我尝试将 boost 的路径设置为“/Users/jacobschoen/Library/boost_1_45_0”和“/Users/jacobschoen/Library/boost_1_45_0/stage/lib”。两者都不起作用。

根据要求,上述代码的编译器错误是:

**** Build of configuration Debug for project test ****

make all 
Building file: ../src/test.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test.d" -MT"src/test.d" -o"src/test.o" "../src/test.cpp"
../src/test.cpp:10:32: warning: boost/filesystem.hpp: No such file or directory
../src/test.cpp: In function 'int main()':
../src/test.cpp:13: error: 'boost' has not been declared
../src/test.cpp:13: error: expected `;' before 'path'
../src/test.cpp:14: error: 'boost' has not been declared
../src/test.cpp:14: error: 'path' was not declared in this scope
make: *** [src/test.o] Error 1

如果有人有任何进一步的建议,我仍在尝试。

第二次更新根据 rholmes 的建议,我添加了一个包含库以及链接器列表和库搜索路径。所以现在编译错误是:

**** Build of configuration Debug for project test ****

make all 
Building target: test
Invoking: MacOS X C++ Linker
g++ -L/Users/jacobschoen/Library/boost_1_45_0 -o "test"  ./src/test.o   -lboost_system -lboost_filesystem
ld: library not found for -lboost_system
collect2: ld returned 1 exit status
make: *** [test] Error 1

有任何想法吗?


只是想弄清楚什么是真正有效的,因为它是由一些答案拼凑而成的。

  1. 下载 boost 文件并将其解压到您想要放置的位置。
  2. 在终端中导航到该目录并运行./bootstrap.sh
  3. 完成后运行./bjam(这需要一段时间,所以去抽烟并喝杯咖啡)
  4. 打开 Eclipse 项目并转到“项目”>“属性”>“C/C++ 构建”>“设置”
  5. Click on MacOS X C++ Linker > Libraries. You should see a split window with the top being for 'Libraries (-l)'. In this section add both boost_system and boost_filesystem. In the bottom section it should be for 'Library Search Path (-L)'. Here you want to put the path to the stage/lib directory inside where you extracted the boost download. It should look similar to below:alt text
  6. Click GCC C++ Compiler > Includes. This will be a single pane where it says 'Include Paths (-I)', well I think it is an I as he font is weird and could be a lower case l also. Anyway in that section add the path to where you put boost without the stage/lib part. It should look like below:alt text

现在一切都应该可以毫无问题地编译,如果您需要使用任何其他 boost 库,只需将其添加到 boost_filesystem 和 boost_system 所在的链接器部分即可。享受。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 Boost 库添加到 OS X Eclipse 中的 C++ 项目 的相关文章

随机推荐