简体   繁体   English

如何在OSX中安装Boost

[英]How to install boost in OSX

What I have done before: 我之前做过的事情:

(1) download .tar (1)下载.tar

(2) unzip (2)解压缩

(3) cd to the path (3)cd到路径

(4) ./bootstrap.sh (4)./bootstrap.sh

(5) wait until: (5)等到:

The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

/Users/lvzhi107/Downloads/boost_1_57_0

The following directory should be added to linker library paths:

/Users/lvzhi107/Downloads/boost_1_57_0/stage/lib

(6) ./b2 install (6)./ b2安装

but it shows : 但它显示:

...failed common.copy /usr/local/lib/libboost_wave.a...
...failed updating 65 targets...
...skipped 11349 targets...

then I wrote a code: test.cpp 然后我写了一个代码: test.cpp

#include<iostream>
#include<boost/format.hpp>
int main()
{
    boost::format("hello world");
}

run it using g++: g++ test.cpp but it still wrong: 使用g ++: g++ test.cpp运行它,但仍然错误:

test.cpp:2:9: fatal error: 'boost/format.hpp' file not found
#include<boost/format.hpp>
        ^
1 error generated.

Could you tell me how to solve it?Thanks. 您能告诉我如何解决吗?

You need to add the location of the include path in the compile command (this is where header files would be located). 您需要在compile命令中添加include路径的位置(这是头文件所在的位置)。 Often the compile command needs to have the include path, and would be similar to this: 通常,compile命令需要包含路径,并且类似于以下内容:

g++ -I/usr/local/include test.cpp

However, the standard include path location above might not be the correct location, since on step (5): 但是,由于在步骤(5)上,上述标准包含路径位置可能不是正确的位置:

The following directory should be added to compiler include paths: 以下目录应添加到编译器包含路径:

/Users/lvzhi107/Downloads/boost_1_57_0 /用户/ lvzhi107 /下载/ boost_1_57_0

So in that case you would likely use: 因此,在这种情况下,您可能会使用:

g++ -I/Users/lvzhi107/Downloads/boost_1_57_0 test.cpp

If you encounter the same error again it might be recommended to step back and read the documentation more in depth, or perhaps use another means of installing boost such as MacPorts. 如果再次遇到相同的错误,建议您退一步并更深入地阅读文档,或者使用其他安装Boost的方法,例如MacPorts。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM