如何设置 Boost 以在 Xcode 上编译和链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9574554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:32:19  来源:igfitidea点击:

How to set up Boost to compile and link on Xcode

c++xcodeboost

提问by Andrew

I have tried to install Boost C++ library on Xcode 3.1.4 (Mac OS X Leopard) many different ways and all have failed. Recently I came across the Homebrew package installer and used this to install boost.

我曾尝试以多种不同方式在 Xcode 3.1.4 (Mac OS X Leopard) 上安装 Boost C++ 库,但都失败了。最近我遇到了 Homebrew 软件包安装程序并用它来安装 boost。

How do you install Boost on MacOS?

如何在 MacOS 上安装 Boost?

However when I try and include a boost library in a project, for example

但是,当我尝试在项目中包含一个 boost 库时,例如

"boost/lambda/lambda.hpp"

“升压/拉姆达/拉姆达.hpp”

I get: "error: boost/lambda/lambda.hpp no such file or directory"

我得到:“错误:boost/lambda/lambda.hpp 没有这样的文件或目录”

Have tried setting "/usr/local/boost_1_47_0" in the library search path. I cannot seem to find any header files for the boost library. So set header search path to the same "/usr/local/boost_1_47_0". I wonder if Homebrew has properly installed the boost libraries? I installed again and got a warning that boost is already installed.

已尝试在库搜索路径中设置“/usr/local/boost_1_47_0”。我似乎找不到 boost 库的任何头文件。因此,将标题搜索路径设置为相同的“/usr/local/boost_1_47_0”。我想知道 Homebrew 是否正确安装了 boost 库?我再次安装并收到警告,提示已经安装了 boost。

Has anyone else had experience with getting Xcode to work with boost? Been struggling with this for a couple of days now and I am just about ready to give up and go to Eclipse on Ubuntu.

有没有其他人有过让 Xcode 与 boost 一起工作的经验?已经为此苦苦挣扎了几天,我准备放弃并在 Ubuntu 上使用 Eclipse。

回答by ComicSansMS

Most Boost libraries are header-only, so you only need to set the include path.

大多数 Boost 库都是头文件,所以你只需要设置包含路径。

In case of the Homebrew version, Boost headers are installed to /usr/local/include/, which should be in the XCode include path by default. Verify that the files were installed correctly (e.g. the lambda header should be at /usr/local/include/boost/lambda/lambda.hpp) and verify that XCode has its include path set up accordingly.

在 Homebrew 版本的情况下,Boost 头文件被安装到/usr/local/include/,默认情况下它应该在 XCode 包含路径中。验证文件是否已正确安装(例如 lambda 标头应位于/usr/local/include/boost/lambda/lambda.hpp)并验证 XCode 是否已相应设置其包含路径。

On a related note, take a look at CMakefor configuring your build. It not only takes care of configuring libraries for build, it also allows easy switching between different toolchains (in your case XCode on Mac and Eclipse on Ubuntu).

在相关说明中,查看用于配置构建的CMake。它不仅负责为构建配置库,还允许在不同的工具链之间轻松切换(在您的情况下,Mac 上的 XCode 和 Ubuntu 上的 Eclipse)。