我一直在尝试使用 eclipse 使用 boost 文件系统库来设置 C++ 项目。我跟着these http://www.technoboria.com/2009/07/simple-guide-to-installing-boost-on-mac-os-x/在我的系统上安装 boost 的说明。方向差不多
- 下载
- extract
- 运行 bootstrap.sh
- 运行 ./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
有任何想法吗?