【问题标题】:OSX "clang++ -lboost_mpi"` ->"ld: library not found for -lboost_mpi" after brew install boost --with-mpiOSX“clang++ -lboost_mpi”`->“ld: library not found for -lboost_mpi” brew install boost --with-mpi
【发布时间】:2015-08-22 08:11:28
【问题描述】:

使用 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)

【问题讨论】:

    标签: c++ macos boost homebrew boost-mpi


    【解决方案1】:

    在 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 会导致多线程版本使用-mt 进行后修复。

    这意味着你的 boost_mpi 库被称为:boost_mpi-mt,这就是你应该链接到的,所以你要链接到的库是libboost_mpi-mt,所以选项是-lboost_mpi-mt

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

    如果你想获得一个未标记的构建(即没有 -mt),那么编辑 boost 配方(使用brew edit boost)并将--layout=tagged 替换为--layout=system。不过,这可能会导致其他事情发生故障。

    【讨论】:

    • 此外,我建议使用mdfind -name libboost_mpi 而不是locate,主要是因为聚光灯索引几乎可以立即进行,而定位依赖于计划的更新周期
    • 感谢您的出色回答!虽然我确实觉得这很有启发性,但brew install boost --with-mpi --without-single --layout=system 并没有解决我的问题(我更新了我的问题以反映这一点)。
    • 抱歉,我应该更清楚一点 - 您必须 编辑 提升公式并更改提及 --layout=tagged 的行。当传入brew install 命令时,它实际上并没有使用该选项。如果您不想重建 boost,则应使用 -lboost_mpi-mt 链接
    猜你喜欢
    • 1970-01-01
    • 2016-05-21
    • 2013-12-17
    • 2015-06-15
    • 2016-04-14
    • 1970-01-01
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多