OSX “clang++ -lboost_mpi”` ->“ld: library not foun

2019-09-08 05:08发布

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
                

1条回答
Root(大扎)
2楼-- · 2019-09-08 06:03

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.

查看更多
登录 后发表回答