0

After installing boost with mpi support using brew I still get the error ld: "library not found for -lboost_mpi" when I run clang++ -lboost_mpi. What can I do to overcome this? I installed boost using brew:

$ brew install boost --with-mpi --without-single
==> Downloading https://downloads.sourceforge.net/project/boost/boost/1.58.0/boost_1_58_0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/boost-1.58.0.tar.bz2
==> ./bootstrap.sh --prefix=/usr/local/Cellar/boost/1.58.0 --libdir=/usr/local/Cellar/boost/1.58.0/lib --without-icu --without-libraries=python
==> ./b2 --prefix=/usr/local/Cellar/boost/1.58.0 --libdir=/usr/local/Cellar/boost/1.58.0/lib -d2 -j4 --layout=tagged --user-config=user-config.jam install t
  /usr/local/Cellar/boost/1.58.0: 10668 files, 300M, built in 10.9 minutes

How can I use clang++ -lboost_mpi successfully?

$ mdfind -name libboost_mpi
/usr/local/Cellar/boost/1.58.0/lib/libboost_mpi-mt.dylib
/usr/local/Cellar/boost/1.58.0/lib/libboost_mpi-mt.a

$ clang++ -I/usr/local/Cellar/boost/1.58.0/lib -lboost_mpi
ld: library not found for -lboost_mpi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
bfontaine
  • 18,169
  • 13
  • 73
  • 107
kilojoules
  • 9,768
  • 18
  • 77
  • 149

1 Answers1

3

The default behaviour when you're building boost with brew on OSX is a tagged build - if you looked a the build output you would have seen something like:

./b2 --prefix=/usr/local/Cellar/boost/1.58.0 --libdir=/usr/local/Cellar/boost/1.58.0/lib -d2 -j8 --layout=tagged --user-config=user-config.jam install threading=multi link=shared,static

and the --layout=tagged causes multi-threaded versions to be post-fixed with -mt.

This means your boost_mpi library is called: boost_mpi-mt, and that's what you should link to, so the library you're linking to is libboost_mpi-mt, so the option is -lboost_mpi-mt.

You could also have looked in the /usr/local/Cellar/boost/1.58.0/lib directory for the library - it would have hinted at this as well.

If you want to get an untagged build (i.e. without the -mt) then edit the boost recipe (using brew edit boost) and replace the --layout=tagged with --layout=system. This may cause other things to break, though.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • 1
    In addition, I'd recommend using `mdfind -name libboost_mpi` rather than `locate`, primarily because spotlight indexes pretty much immediately while locate relies on the scheduled update period – Anya Shenanigans Jun 08 '15 at 15:45
  • Thanks for the excellent answer! Although I did find this illuminating, `brew install boost --with-mpi --without-single --layout=system` did not solve my problem (I updated my question to reflect this). – kilojoules Jun 08 '15 at 18:49
  • Apologies, I should have been more clear - you have to *edit* the boost formula and change the line that mentions `--layout=tagged`. It doesn't actually make use of the option when passed in to the `brew install` command. If you don't want to rebuild boost, you should link using `-lboost_mpi-mt` – Anya Shenanigans Jun 08 '15 at 18:51