Click here to Skip to main content
12,820,100 members (24,114 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 1 Mar 2013

Boost vs OSX / iOS / XCode

, 26 Mar 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
How to develop using C++/Boost on the Mac using XCode


C++ without Boost is like Oktoberfest without brass music & bier- no fun at all. This is true for the Mac, too, but there are some specific problems.


Getting to work with boost under XCode did cost me some grey hair. Here are my experiences which might save you some time.

Building Boost

Obtain the sources from or sourceforge. Read the instructions on how to build. 1_52 is broken for Mac, see here. 1_51 and 1_53 are fine. Symptom you are affected are messages like "error: constexpr function never produces a constant expression".

Building for Both 32/64 bits

If you need to support both architectures, you can do it if you create a file named ~/user-config.jam with these two lines:

using darwin : : : <compileflags>"-arch x86_64 -arch i386" ;
using clang  : : : <compileflags>"-arch x86_64 -arch i386 -stdlib=libc++" ;

The first line makes sure a regular build is with both 64/32 bit libraries. The libraries such created are Mac "fat" libraries, containing both variants in one file.

Building for CLang

If you build like instructed on the boost website, the libraries are fine for g++, but not clang++, the compiler used by default by XCode. You can build libraries for use with XCode with this line:

bjam toolset=clang

This is made possible by the second line in user-config.jam. Again, this builds fat binaries. If you try to build a binary with clang++ , but your boost is build with g++, you will get error messages like:

"Undefined symbols for architecture i386:
 "boost::program_options::to_internal(std::__1::basic_string<char, std::__1::char_traits<char>, 
 std::__1::allocator<char> > const&)", referenced from:”

Building for iOS

If you need boost for iOS, you can find instructions by Pete Goodliffe here. Pete wrote a nifty shell script to do the job which you can find here. It's a bit dated, though, and I had to make a few minor changes so it works with the current SDK version 6.1 (as of Mar. 2013). The updated version of the script is attached to this tip. This zip includes a user-config.jam which you need to put in your home directory.

Using Boost

Note that both boost and some Apple includes define a Macro "check”. This can cause errors like the one encountered here. I circumvent this problem by adding:

#undef check

just before I include the boost headers. The Apple headers Carbon/Carbon.h etc. are all included before. There is another, maybe better possibility described in AssertMacros.h.

*      Prior to Mac OS X 10.6 the macro names used in this file conflicted with some
*      user code, including libraries in boost and the proposed C++ standards efforts,
*      and there was no way for a client of this header to resolve this conflict. Because
*      of this, most of the macros have been changed so that they are prefixed with
*      __ and contain at least one capital letter, which should alleviate the current
*      and future conflicts.  However, to allow current sources to continue to compile,
*      compatibility macros are defined at the end with the old names.  A tops script
*      at the end of this file will convert all of the old macro names used in a directory
*      to the new names.  Clients are recommended to migrate over to these new macros as
*      they update their sources because a future release of Mac OS X will remove the
*      old macro definitions ( without the double-underscore prefix ).  Clients who
*      want to compile without the old macro definitions can define the macro
*      included.

You are affected by this if you encounter errors like:

Expected member name in has_binary_operator.hpp 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Norbert Schneider
Software Developer (Senior)
Germany Germany
Born 1968, got a PhD in engineering. Been doing FEM type simulations in a varity of fields. Now working for a company that makes security software (Bring your own device solutiuons) for a varity of platforms.

You may also be interested in...

Comments and Discussions

GeneralThx Pin
_tourniquet_16-Feb-14 2:57
member_tourniquet_16-Feb-14 2:57 
Questionthe file is not downloadable Pin
sarin sukumar A26-Mar-13 15:30
membersarin sukumar A26-Mar-13 15:30 
AnswerRe: the file is not downloadable Pin
Norbert Schneider18-Apr-13 2:48
memberNorbert Schneider18-Apr-13 2:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 27 Mar 2013
Article Copyright 2013 by Norbert Schneider
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid