在 xcode 中包含 boost

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10141983/
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-09 04:21:55  来源:igfitidea点击:

Include boost in xcode

xcodeboost

提问by Heba

I could not include boost in xcode. I used the build instructions from the Boost documentation and wrote the search paths in xcode /usr/local/lib and /usr/local/include.

我无法在 xcode 中包含 boost。我使用了 Boost 文档中的构建指令,并在 xcode /usr/local/lib 和 /usr/local/include 中编写了搜索路径。

Any help please !

请任何帮助!

采纳答案by instazz

I'm using boost with Xcode 3.2.1 on mac os 10.6.8

我在 mac os 10.6.8 上使用 boost 和 Xcode 3.2.1

I had problems with using boost and Xcode today, finally I managed to make it work so I hope this helps:

我今天在使用 boost 和 Xcode 时遇到了问题,最后我设法让它工作,所以我希望这会有所帮助:

  1. download boost, I got the 1.52.0 today, untar it

  2. install boost:

    at first I couldn't do the ./bootstrap.sh, it stopped after the first few lines. After some googling, I got the answer, it was because when I installed Xcode a long time ago, for some reason I didn't check the “Unix development" in the install options. At this point, reinstall a newer version of Xcode and check the "unix development line"

    after that, the ./bootstrapand ./b2install worked fine

  3. the lambda example:

    at this point, the first example should work fine, if it doesn't try adding /usr/local/includein the project settings/header search path

  4. using thread or something else that requires to be built

    threads require a specific dylib to work: libboost_system.dylib. on my system it was located in /usr/local/libafter the ./b2 installthingy

    in the left part of the GUI, you can right click anywhere and select Add Existing File

    if the file is hidden you can find a shortcut to get to usr/local/lib in the directory /Developer/SDKs/MacOSX10.6.sdk/usr/local

  1. 下载提升,我今天得到了 1.52.0,解压它

  2. 安装提升:

    起初我做不到./bootstrap.sh,它在前几行之后停止了。google了几下,得到了答案,是因为很久以前安装Xcode的时候,不知为何没有勾选安装选项中的“Unix开发”。此时,重新安装一个新版本的Xcode,然后检查“unix 开发线”

    在那之后,./bootstrap./b2安装工作正常

  3. 拉姆达示例:

    此时,第一个示例应该可以正常工作,如果它不尝试添加/usr/local/include项目设置/标题搜索路径

  4. 使用线程或其他需要构建的东西

    线程需要特定的 dylib 才能工作:libboost_system.dylib。我的系统上它位于/usr/local/lib./b2 install

    在 GUI 的左侧,您可以右键单击任意位置并选择添加现有文件

    如果文件被隐藏,你可以在目录中找到一个快捷方式来访问 usr/local/lib /Developer/SDKs/MacOSX10.6.sdk/usr/local

once the libboost_system.dylibdoes appear in the Groups and Files part of the GUI, it should work

一旦libboost_system.dylib确实出现在 GUI 的组和文件部分,它应该可以工作

回答by henrikstroem

I have spent a long time trying to make this work. I could not make it work using the download from the Boost project homepage, so I used homebrewinstead:

我花了很长时间试图使这项工作。我无法使用 Boost 项目主页上的下载使其工作,所以我改用自制软件

After homebrew is installed, I installed Boost using:

安装自制软件后,我使用以下方法安装了 Boost:

brew install boost 

or, if you don't have python installed, using:

或者,如果您没有安装 python,请使用:

brew install boost --without-python

Without the --without-python it would not install on my machine.

没有 --without-python 它不会安装在我的机器上。

  1. In XCode (4.3.3), select the project file in the left sidebar (top most), and select it again in the project pane.
  2. Select the Build Settings tab, and select All.
  3. Under Search Paths, add the header search path /usr/local/Cellar/boost/1.49.0/include/and check the box. The path should now show in the Build Settings.
  1. 在 XCode (4.3.3) 中,在左侧边栏中(最顶部)选择项目文件,然后在项目窗格中再次选择它。
  2. 选择“构建设置”选项卡,然后选择“全部”。
  3. 在搜索路径下,添加标题搜索路径/usr/local/Cellar/boost/1.49.0/include/并选中该框。该路径现在应该显示在构建设置中。

Now, you can use:

现在,您可以使用:

#include <boost/regex.hpp>

or whatever you need from the Boost package.

或者任何你需要的 Boost 包。



In case you have boost already installed, use $ brew info boostto get the correct path:

如果您已经安装了 boost,请使用$ brew info boost获取正确的路径:

boost: stable 1.60.0 (bottled), HEAD
Collection of portable C++ source libraries
https://www.boost.org/
/usr/local/Cellar/boost/1.60.0_1 (11,139 files, 436.5M) *
  Poured from bottle
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/boost.rb

回答by neoneye

I followed henrikstroem's great post, like this:

我关注了 henrikstroem 的精彩帖子,如下所示:

Install via homebrew, took less than 3 minutes

通过自制软件安装,耗时不到 3 分钟

mac:~ woz$ brew install boost
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/boost-1.57.0.yosemite.bottle.tar.gz
######################################################################## 100.0%
==> Pouring boost-1.57.0.yosemite.bottle.tar.gz
  /usr/local/Cellar/boost/1.57.0: 10572 files, 439M
mac:~ woz$

Create symlink in your homedir

在您的主目录中创建符号链接

mac:~ woz$ cd
mac:~ woz$ ln -s /usr/local/Cellar/boost/1.57.0 boost_1_57_0
mac:~ woz$ 

Inside Xcode refer to the just created symlink like this

在 Xcode 中,像这样引用刚刚创建的符号链接

Xcode build settings for boost

用于提升的 Xcode 构建设置

For the Header Search Pathsuse $(HOME)/boost_1_57_0/include

Header Search Paths使用$(HOME)/boost_1_57_0/include

For the Library Search Pathsuse $(HOME)/boost_1_57_0/lib

Library Search Paths使用$(HOME)/boost_1_57_0/lib

回答by micfan

mic@mbp: ~/work $ brew install boost
mic@mbp: ~/work $ ls -l /usr/local/include/boost
lrwxr-xr-x  1 mic  wheel  36 Nov 27 01:06 /usr/local/include/boost -> ../Cellar/boost/1.56.0/include/boost

hi, I add /usr/local/includein Header Search Paths(with double click it, but Debug or other sub checks), then

嗨,我加/usr/local/includeHeader Search Paths(与双击它,但调试或其他子检查),然后

#include <boost/asio.hpp>
#include <boost/date_time.hpp>

using namespace boost;

int main() {
    asio::io_service io;

    io.run();
    return 0;
}

worked, :D

工作,:D