如何在 OSX 中安装 boost

How to install boost in OSX

本文关键字:安装 boost OSX      更新时间:2023-10-16

我以前做过的事情:

(1) 下载.tar

(2) 解压缩

(3) 光盘到路径

(4) ./bootstrap.sh

(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 安装

但它显示:

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

然后我写了一个代码:test.cpp

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

使用 G++ 运行它: g++ test.cpp但它仍然是错误的:

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

你能告诉我如何解决它吗?谢谢。

您需要在 compile 命令中添加包含路径的位置(这是头文件所在的位置)。通常,编译命令需要具有包含路径,并且类似于以下内容:

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

但是,上面的标准包含路径位置可能不是正确的位置,因为在步骤 (5) 中:

应将以下目录添加到编译器包含路径中:

/

用户/绿智107/下载/boost_1_57_0

因此,在这种情况下,您可能会使用:

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

如果您再次遇到相同的错误,则可能建议退后一步并更深入地阅读文档,或者使用其他安装boost的方法,例如MacPorts。