【发布时间】:2011-05-25 00:27:30
【问题描述】:
我一直在尝试使用 Eclipse 使用 boost 文件系统库来设置 C++ 项目。我按照these 的指示在我的系统上安装了 boost。方向很远
- 下载
- 提取
- 运行 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 站点。它说通过转到项目属性并添加“boost_filesystem”来将boost库添加到链接器。这个我试过了,还是不行。
谁能指出我正确的方向或提示我如何在 Eclipse 项目中设置 Boost?
我是 C++ 和 Eclipse 的新手,我的大部分经验是在 Java 中使用 Netbeans。所以我现在很迷茫。
更新
我只是想根据给出的答案更新我尝试过的内容。
根据 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
有什么想法吗?
【问题讨论】: