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

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

使用 brew 安装带有 mpi 支持的 boost 后,当我 运行 clang++ -lboost_mpi 时,我仍然收到错误 ld: "library not found for -lboost_mpi"。我该怎么做才能克服这个问题?我使用 brew 安装了 boost:

$ 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

如何才能成功使用clang++ -lboost_mpi

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

当您在 OSX 上使用 brew 构建 boost 时,默认行为是标记构建 - 如果您查看构建输出,您会看到如下内容:

./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

--layout=tagged 导致多线程版本被 post 固定为 -mt

这意味着您的 boost_mpi 库被称为:boost_mpi-mt,这就是您应该 link 的内容,因此您 link 要访问的库是 libboost_mpi-mt,所以选项是-lboost_mpi-mt.

您也可以查看库的 /usr/local/Cellar/boost/1.58.0/lib 目录 - 它也会提示这一点。

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.