OSX "clang++ -lboost_mpi"` ->"ld: library not found for -lboost_mpi" after brew install boost --with-mpi

1.4k Views Asked by At

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)
1

There are 1 best solutions below

3
On BEST ANSWER

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.