# boost with XCode

Sometime ago I was trying to port one of my experiments on Mac OS X. The application relies on boost library, so there was need to get started with boost on Mac. And I wanted to use XCode all the way along. Coming from Windows meant browsing thru XCode build settings to figure out what goes where. Visual Studio Property Pages and XCode Settings don’t match really well, from UI point of view.

XCode puts the compiler application somewhere in deep guts of \Developer directory, so copying the boost libraries was not really an option. Mac OS X being UNIX underneath meant I had a global include/lib/bin directory where I can put boost libraries once built. What follows next is visual summary of building and installing boost on Mac OS X.

It starts with boot-strapping boost build engine:

Then comes the part of building and installing boost libraries. Boost builds shared libraries on UNIX systems (though it has option to build static libraries only on windows).

Once it was done building and putting libraries and headers in appropriate global directories now I had to move to XCode to provide details about which libraries were to be used and where to find them. The following two images shows I had to specify the header and lib search paths and then had to specify the library to link:

Once all of this was set, now I could successfully compile and link code that used boost libraries. In this case I am using chrono, which depends on system and chrono libraries.

All of this can be done from command line as well and the command would be:

mbp:blog sarang$clang boostchrono.cpp -std=c++11 -I/Users/Sarang/boost/boost_1_55_0 -L/Users/Sarang/boost/boost_1_55_0/stage/lib -lc++ -lboost_chrono -lboost_system -o boostchrono mbp:blog sarang$ ./boostchrono
Hello World!
{1408590201330000000;0;0} nanoseconds since process start-up


Where

-std=c++11 - for using C++11 features from clang compiler
-I specifies the path for header include directory
-L specifies the path for library location directory
-l specifies which particular libraries to be linked with
-lc++ for std::cout, -lboost_chrono and -lboost_system for using boost::chrono
-o boostchrono is the resultant executable

Thats all for now. I will try to cover more details on creating Shared objects (dylib on Mac OS X, so on Linux) and symbol versioning in future posts.