Build Boost on Mac with Xcode

35,423

Solution 1

The easiest way I've found to do it is to install MacPorts, then you can install/build Boost via a single command:

sudo port install boost

Plus you get similar access to other open source software. The only downside I've found is that, like any other package management system, they are not always up to date with the latest version.

If you prefer Homebrew as your package manager, the command is:

brew install boost

Solution 2

I don't know how to use Boost from XCode (I'm not a Mac programmer), but building boost is usually done through their own build tool, bjam.

They have a guide to building boost here, and you can download the latest version of bjam here

Once it is built, you reference it from Xcode the same way you would any other library. The boost/include should be added to your include path, and the libraries in boost/lib can be referenced for the boost libs that require it.

Solution 3

To build boost on a mac, follow the unix variants getting started page (http://www.boost.org/doc/libs/1_39_0/more/getting_started/unix-variants.html). You won't use Xcode directly to perform the build, but once complete you can add the boost include paths and dylib's to your Xcode project.

Solution 4

su - root

enter root password and then run below as root

/opt/local/bin/port install boost

If you have never logged in as root or forgotten your password, here are the steps to reset root password

http://support.apple.com/kb/HT1528?viewlocale=en_US&locale=en_US

Solution 5

I found that to build Boost 1.41.1 on MacOS, you need to do the following:

  1. Download boost 1.46.1 from here: http://sourceforge.net/projects/boost/files/boost/1.46.1/
  2. Unpack the file
  3. Open terminal, cd to the install directory, and do the following:

chmod u+x configure.sh

cd tools/build/v2/engine/src

chmod u+x build.sh

Then go back to the install directory, and:

./configure.sh

If that runs successfully, it will tell you to run:

./bjam

That's it.. for whatever reason, I needed to set those permissions manually before it would work.

Share:
35,423
Admin
Author by

Admin

Updated on January 12, 2022

Comments

  • Admin
    Admin over 2 years

    I've recently got acquainted with Boost library and I'd like to use it in my Xcode project. But sadly there is no HowTo or FAQ on how to do it :(

    What's the sequence of actions to build and use Boost libraries in Xcode?

  • oz10
    oz10 about 15 years
    You need to follow the instructions for building on UNIX.
  • josesuero
    josesuero about 15 years
    "didn't help"? What do you mean by that?
  • Sergiy Belozorov
    Sergiy Belozorov almost 14 years
    That does not describe how to build a program with Boost in XCode. It only describes how to build the library itself.
  • Aaron
    Aaron over 13 years
    Many libraries are header only hpp but many need to be built separately. See: boost.org/doc/libs/1_45_0/more/getting_started/…
  • Tomas Andrle
    Tomas Andrle about 13 years
    This works for my Debug builds but I'm having problems with Release builds. Does that work for you?
  • Ferruccio
    Ferruccio about 13 years
    @TomA: It's worked for me before. What kind of problems are you having?
  • Tomas Andrle
    Tomas Andrle about 13 years
    ld ignoring file /opt/local/lib/libboost_filesystem.dylib, file was built for unsupported file format which is not the architecture being linked (i386)... and after that several undefined symbols from the system and filesystem boost libraries that fail to link. Works for "Build for Running", fails for "Build for Archiving".
  • andrewz
    andrewz over 12 years
    Not sure if it's clear for all or not (wasn't for me), after installing boost with port you'll find include files under /opt/local/include/boost. Then you can create a source tree entry under preferences in Xcode, ex. LIBRARY_OPT_LOCAL_INCLUDE as /opt/local/include, include $(LIBRARY_OPT_LOCAL_INCLUDE) non-recursively under User Header Search Paths in the project, and then include boost header files in your source code with the boost prefix, ex. #include <boost/array.hpp>
  • polyclick
    polyclick almost 12 years
    @andrewz, thanks for the explain. But, for some reason, I had to use this path: /opt/local/include so, without the "/boost" at the end. Just saying for someone that had the same problem.
  • eb80
    eb80 about 11 years
    I added in the header files, but XCode does not recognize them in the format <boost/xyz.hpp>. The files are in the directory, but are not recognized. This does not help.
  • keyser
    keyser almost 11 years
    @bitshiftcop Same here! +1
  • Patricia
    Patricia over 10 years
    Ferruccio and @andrewz - YOU ARE MY HEROES!!! Thanks. That was easy! After spending hours and hours on-line trying to get this to work. And. bitshiftcop, I had to leave off the /boost at the end and use it in the include statements, too. Thank you, thank you, thank you. :-)
  • Patricia
    Patricia over 10 years
    I realize this comment is late. But in case somebody else gets to this point and still has issue. Look at Ferruccio's answer, above. Add in the comments by andrews and bitshiftcop. Xcode isn't recognizing the includes because you need to add the path to your Target --> Search Paths --> Header Search Paths list. The path should be /opt/local/include. I hope this helps somebody.
  • Patricia
    Patricia over 10 years
    @TomA - Did you ever get this working? I'm having similar issues only with the build. I followed Ferruccio's and andrewz's instructions and everything seemed hunky-dory until I tried to build. Root error is Undefined symbols for architecture x86_64. Please HELP!!! I have a question here: stackoverflow.com/questions/21590507/…
  • Tomas Andrle
    Tomas Andrle over 10 years
    @Lucy not reliably. See my answer below for a solution that worked better for me.
  • Ky -
    Ky - almost 4 years
    The link at the core of this answer is a 404 now. Is there a modern version that folks can use today?