将升压库添加到OS X Eclipse中的C ++项目 [英] Adding Boost Library to a C++ project in OS X Eclipse

查看:125
本文介绍了将升压库添加到OS X Eclipse中的C ++项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用eclipse的boost文件系统库来获取C ++项目设置。我遵循这些在我的系统上安装boost的方向。


  1. 下载

  2. 提取

  3. 运行bootstrap.sh

  4. 运行./bjam架构=组合

罚款,没有错误。然后,我启动了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\\\
,result);
return 0;
}

这只是一个简单的事情,以确保它的设置正确。当然,我试图在这一点上编译,失败了。做了一些搜索,发现这个网站。它表示通过转到项目属性并添加boost_filesystem将boost库添加到链接器。我试过了这件事,没有办法。



有人可以指出我正确的方向,或者给我一个提示如何设置Boost一个Eclipse项目?



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



更新



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



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



根据rve的建议,我将升级库的路径添加到库搜索路径。当这不行我清除了链接器列表,并尝试使用库搜索路径。这也没有起作用。



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



在所有这些中,我尝试将路径提升为'/ Users / jacobschoen / Library / boost_1_45_0'和'/ Users / jacobschoen / Library / boost_1_45_0 / stage / lib目录。没有工作。



根据请求,上述代码的comiler错误是:

  ****构建配置Debug for project test **** 

make all
构建文件:../src/test.cpp
调用:GCC C ++编译器
g ++ -O0 -g3 -Wall -c -fmessage-length = 0 -MMD -MP -MFsrc / test.d-MTsrc / test.d-osrc / test。 o../src/test.cpp
../src/test.cpp:10:32:warning:boost / filesystem.hpp:没有这样的文件或目录
../src /test.cpp:在函数'int main()'中:
../src/test.cpp:13:错误:'boost'尚未声明
../src/test.cpp :13:error:expected';'before'path'
../src/test.cpp:14:error:'boost'尚未声明
../src/test.cpp: 14:error:'path'未在此范围内声明
make:*** [src / test.o]错误1

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



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

  ****构建配置Debug for project test **** 

make all
构建目标:test
调用:MacOS X C ++链接器
g ++ -L / Users / jacobschoen / Library / boost_1_45_0 -otest./src/test。 o -lboost_system -lboost_filesystem
ld:找不到-lboost_system的库
collect2:ld返回1退出状态
make:*** [test]错误1

任何想法?

解决方案

确定你在Eclipse中这样做,但在Eclipse的include路径下应该是主要的boost目录(/ Users / jacobschoen / Library / boost_1_45_0?)的路径。编译器行应该有如下的内容,我想:



调用:GCC C ++编译器



g ++ -I / Users / jacobschoen / Library / boost_1_45_0 -O0 -g3 -Wall -c -fmessage-length = 0 -MMD(etc ..)



更新:看看我的系统,你的链接器路径可能更合适:



-I / Users / jacobschoen / Library / boost_1_45_0 / stage / lib



当然,依赖于您如何安装和构建boost - 这是我最近尝试使用完整的源代码。取决于你如何获得提升,这可能是也可能不会有所不同。我最近在我的Mac上重新启动了64位,并没有太多时间尝试它....


I am have been attempting to get a C++ project setup using boost file system library using eclipse. I followed these directions to install boost on my system. The directions where pretty much

  1. download
  2. extract
  3. run bootstrap.sh
  4. run ./bjam architecture=combined

That seemed to go fine, no errors. I then fired up eclipse and created a new test project called test with a single file called test.cpp. The code in it is:

#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 is just something simple to make sure it is all set up correctly. Of course I tried to compile at this point and it failed. Did some googling and found this site. It said to add the boost library to the linker by going to project properties and adding "boost_filesystem". I tried this, and well it didn't work.

Can someone point me in the right direction or give me a hint to how to set up Boost in an Eclipse project?

I am new to C++ and Eclipse, and most my experience is in Java with Netbeans. So I am pretty lost at the moment.

UPDATE

I just wanted to update on what I have tried based on the answers given.

Based on Alex's suggestion I added boost_system and boost_filesystem to the linker list. I was still getting the same compiler errors.

Following the suggestion from rve I added the path to the boost libraries to the Library search path. When this did not work. I cleared out the linker list and tried it with just the library search path. This also did not work.

I then cleared the Library search path. I then manually edited the command on the linker window to be 'g++ -L/Users/jacobschoen/Library/boost_1_45_0/stage/lib -lboost -lboost_filesystem'. This also did not work.

In all of these I tried setting the path to boost to be '/Users/jacobschoen/Library/boost_1_45_0' and '/Users/jacobschoen/Library/boost_1_45_0/stage/lib'. Neither worked.

As requested the comiler error for the above code is:

**** 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

If any one has any further suggestions I am still trying.

Second Update On a suggestion by rholmes I added an include library along with the linker list and library search path. So now the compile error is:

**** 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

Any ideas?

解决方案

Not sure where you do this in Eclipse these days, but under the include paths for Eclipse should be the path to the main boost directory (/Users/jacobschoen/Library/boost_1_45_0?). The compiler line should have something like the following in it, I would think:

Invoking: GCC C++ Compiler

g++ -I/Users/jacobschoen/Library/boost_1_45_0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD (etc..)

Update: Looking at my system, the linker path on yours might be more appropriately:

-I/Users/jacobschoen/Library/boost_1_45_0/stage/lib

Depending, of course, upon how you've installed and built boost -- this is with my most recent attempt with a full source build. Depending upon how you obtained boost, this may or may not be different. I recently redid the boost on my Mac for 64 bit and haven't had much time to try it yet....

这篇关于将升压库添加到OS X Eclipse中的C ++项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆