16

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?

Binarian
  • 12,296
  • 8
  • 53
  • 84
  • 1
    Mac (OSX) is just a variant of UNIX. Follow UNIX instructions. – Martin York May 21 '09 at 17:00
  • I followed that post and it didn't work for me. Ferruccio's answer below, did the trick. I'm gaining a real appreciation for MacPorts. It's the magic to getting a lot of things installed correctly. – Patricia Feb 05 '14 at 00:10

8 Answers8

27

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
Ferruccio
  • 98,941
  • 38
  • 226
  • 299
  • This works for my Debug builds but I'm having problems with Release builds. Does that work for you? – Tomas Andrle Apr 12 '11 at 10:14
  • @TomA: It's worked for me before. What kind of problems are you having? – Ferruccio Apr 12 '11 at 12:30
  • 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". – Tomas Andrle Apr 12 '11 at 13:07
  • 5
    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 – andrewz Feb 04 '12 at 13:52
  • 3
    @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. – polyclick Jul 25 '12 at 14:46
  • @bitshiftcop Same here! +1 – keyser Jul 27 '13 at 21:32
  • 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 Feb 05 '14 at 00:06
  • @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: http://stackoverflow.com/questions/21590507/boost-xcode-c-command-line-undefined-symbols-for-architecture-x86-64 – Patricia Feb 06 '14 at 17:27
  • @Lucy not reliably. See my answer below for a solution that worked better for me. – Tomas Andrle Feb 10 '14 at 08:34
6

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.

jalf
  • 243,077
  • 51
  • 345
  • 550
5

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.

equackenbush
  • 136
  • 3
1

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

1

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.

Community
  • 1
  • 1
ch3rryc0ke
  • 2,793
  • 1
  • 22
  • 28
0

Currently I'm very happy with using Pete Goodliffe's script which builds a framework from the Boost source package for both iOS and Mac. Drag and drop it into a project and it works!

There are multiple versions of the script out there. Here's one: https://gist.github.com/faithfracture/c629ae4c7168216a9856/61be257e1c0839c85743777d0687becad9913bf7

Tomas Andrle
  • 13,132
  • 15
  • 75
  • 92
  • The link at the core of this answer is a 404 now. Is there a modern version that folks can use today? – Ky - Jun 30 '20 at 16:01
0

Elaboration of Ferrucio's answer:

  1. Install Boost using MacPorts (sudo port install boost) or Homebrew (brew install boost).

  2. Find the path to the Boost header files (it should be in /opt/homebrew/include if you're using Homebrew).

  3. Add the path to System Header Search Paths in the Build Settings of your Xcode target.

IMPORTANT NOTE: If you add the path to User Header Search Paths instead of System Header Search Paths, as other users suggested, then your code will fail to build, since the Boost files use angled-includes (#include <boost/filename.hpp>) to include each other. Angled-includes are only for including system library headers, and thus they only work if Boost is in the System Header Search Paths.

You can read about the difference between angled-includes and quoted-includes here.

McKinley
  • 1,123
  • 1
  • 8
  • 18
0

For most of the boost libraries, there's nothing to build, it's all in header files. The remainder of the instructions are here.

rlbond
  • 65,341
  • 56
  • 178
  • 228
  • 1
    That does not describe how to build a program with Boost in XCode. It only describes how to build the library itself. – Sergiy Belozorov Aug 08 '10 at 20:59
  • Many libraries are header only hpp but many need to be built separately. See: http://www.boost.org/doc/libs/1_45_0/more/getting_started/unix-variants.html#id22 – Aaron Dec 01 '10 at 18:50
  • I added in the header files, but XCode does not recognize them in the format . The files are in the directory, but are not recognized. This does not help. – eb80 Apr 07 '13 at 19:25
  • 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 Feb 05 '14 at 23:20