3

I have tried to install Boost C++ library on Xcode 3.1.4 (Mac OS X Leopard) many different ways and all have failed. Recently I came across the Homebrew package installer and used this to install boost.

How do you install Boost on MacOS?

However when I try and include a boost library in a project, for example

"boost/lambda/lambda.hpp"

I get: "error: boost/lambda/lambda.hpp no such file or directory"

Have tried setting "/usr/local/boost_1_47_0" in the library search path. I cannot seem to find any header files for the boost library. So set header search path to the same "/usr/local/boost_1_47_0". I wonder if Homebrew has properly installed the boost libraries? I installed again and got a warning that boost is already installed.

Has anyone else had experience with getting Xcode to work with boost? Been struggling with this for a couple of days now and I am just about ready to give up and go to Eclipse on Ubuntu.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrew
  • 31
  • 1
  • 2
  • see http://stackoverflow.com/questions/893841/build-boost-on-mac-with-xcode – Alejandro Mar 06 '12 at 00:43
  • Tried that but none of it worked. As I said I ended up installing with Homebrew as it was the only thing which worked for me. – Andrew Mar 06 '12 at 09:20

1 Answers1

2

Most Boost libraries are header-only, so you only need to set the include path.

In case of the Homebrew version, Boost headers are installed to /usr/local/include/, which should be in the XCode include path by default. Verify that the files were installed correctly (e.g. the lambda header should be at /usr/local/include/boost/lambda/lambda.hpp) and verify that XCode has its include path set up accordingly.

On a related note, take a look at CMake for configuring your build. It not only takes care of configuring libraries for build, it also allows easy switching between different toolchains (in your case XCode on Mac and Eclipse on Ubuntu).

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • I have /usr/local/lib with boost files in it. No usr/local/include only usr/include which has no boost header files. I did a search and lambda.hpp has not been installed anywhere by Homebrew. I will see where I get with cmake and report back later. Thanks! – Andrew Mar 06 '12 at 09:26
  • 1
    In that case it looks like homebrew is to blame. Homebrew will install the headers to `/usr/local/Cellar/boost/` and then create a symlink pointing to the correct include dir at `/usr/local/include/boost`. If the Cellar directory is there but the symlink isn't, it probably did not have rights write in that directory. – ComicSansMS Mar 06 '12 at 13:36
  • You are right the library /usr/local/lib has alias files pointing back to /Cellar/Boost I tried opening up all permissions on folders then unistalling and reinstalling Boost. No luck though, still no header files anywhere. Cmake is not that easy either. http://stackoverflow.com/questions/7347432/installing-boost-with-cmake – Andrew Mar 06 '12 at 17:15
  • I came back and looked at this again today. Something weird, (after installing boost with homebrew) I reinstalled Xcode and everything worked without needing to edit header or library search paths. However if I installed boost after installing Xcode and edited the header/ library search paths the boost libabries are found but the path to standard libraries seem to be lost. I then get an error that Xcode cannot find stdarg.h. – Andrew Mar 11 '12 at 14:26
  • 1
    This might help someone. After more experimentation it seems like Xcode has a problem with searching directories in the tree, even if recursive mode is selected. You need to point the search path right at the directory with the header file in it. – Andrew Mar 14 '12 at 10:44
  • When using boost, it's traditional to include the path from boost down in your include statement, for instance "boost/lambda/lambda.hpp". This helps differentiate this from any other lambda.hpp that might be found somewhere else in your project, or in your numerous include paths. Think of it as namespacing for include files. – Wexxor Aug 16 '12 at 18:35