- 下载
- 提取
- 运行bootstrap.sh
- 运行./bjam architecture=combined
#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 网站。它说要通过进入项目属性并添加 "boost_filesystem" 将 boost 库添加到链接器中。我尝试了一下,结果没成功。
有人能指点我正确的方向或者给我提示如何在 Eclipse 项目中设置 Boost 吗?
我对 C++ 和 Eclipse 都很陌生,我的大部分经验都是在 Netbeans 中使用 Java。所以我现在很迷茫。
更新:
我想更新一下我根据答案尝试过的内容。
基于 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
任何想法?