我是 Homebrew 的新手(我通常使用 Macports,但我正在第二台计算机上试用 Homebrew),我希望安装 openmpi(或 mpich2)包。步骤如下(在安装了Xcode 6的Mac OS X Yosemite上进行):
brew install gcc
brew install openmpi
但是,我怀疑链接可能没有正确完成,原因如下:
缺少/usr/local/bin/gcc 的符号链接(symbolic link):
$ which gcc /usr/bin/gcc $ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix $ which gcc-4.9 /usr/local/bin/gcc-4.9 $ gcc-4.9 --version gcc-4.9 (Homebrew gcc 4.9.2) 4.9.2 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
mpicc 可能已链接到 Apple gcc:
$ which mpicc /usr/local/bin/mpicc $ mpicc --version Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix
我的问题如下:
如何获得
/usr/local/bin/gcc
符号链接(symbolic link)?还是 Homebrew 出于某些原因故意避免这种情况?例如如果 Homebrew 正在使用假定在路径中的 Apple gcc 编译其所有包,那么将路径更改为 gcc-4.9 是否意味着 Homebrew 现在改为使用 gcc-4.9 编译其包?Homebrew 安装的 Open MPI 是否链接到 Apple gcc(而不是 Homebrew gcc)?如果是,是否可以(或建议)更改链接?
或者,修复链接的必要性有多大?如果我选择不修复它,我会遇到某些问题吗?例如,我正在考虑使用
ln -s
强制创建/usr/local/bin/gcc
符号链接(symbolic link)。但这是个好主意吗 (*)?
(*) 我知道可能有 issues when linking object files created by different compilers .因此,对于 (1)、(2) 和 (3),我希望找到一种解决方案,避免组合使用不同的编译器(一些使用 gcc-4.9,一些使用 Apple gcc)创建目标文件。
最佳答案
您需要执行以下操作:
1) 为 homebrew 添加环境变量(您也可以将这些行添加到您的 ~\.bashrc
):
$ export HOMEBREW_CC=gcc-4.9
$ export HOMEBREW_CXX=g++-4.9
2) 从源代码重建并重新安装 openmpi
及其依赖项
$ brew reinstall openmpi --build-from-source
3) 最后你会收到如下信息:
==> Reinstalling open-mpi
==> Using Homebrew-provided fortran compiler.
This may be changed by setting the FC environment variable.
==> Downloading http://www.open-mpi.org/software/ompi/v1.8/downloads/openmpi-1.8.
Already downloaded: /Library/Caches/Homebrew/open-mpi-1.8.4.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/open-mpi/1.8.4 --disable-silent-rules
==> make all
==> make check
==> make install
Warning: open-mpi dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
🍺 /usr/local/Cellar/open-mpi/1.8.4: 785 files, 23M, built in 41.2 minutes
$ mpicc --showme
gcc-4.9 -I/usr/local/Cellar/open-mpi/1.8.4/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.4/lib -lmpi
在我的 MacBook 上,我与 XCode 6.2 有一些冲突,这些冲突在 this instructions 之后得到解决。
如果你想安装mpich
$ unlink openmpi
$ brew unlink gcc
$ brew install homebrew/versions/gcc5
$ brew install mpich --build-from-source
$ mpicc -v
mpicc for MPICH version 3.2
Using built-in specs.
COLLECT_GCC=gcc-5
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc5/5.4.0/libexec/gcc/x86_64-apple-darwin14.5.0/5.4.0/lto-wrapper
Target: x86_64-apple-darwin14.5.0
Configured with: ../configure --build=x86_64-apple-darwin14.5.0 --prefix=/usr/local/Cellar/gcc5/5.4.0 --libdir=/usr/local/Cellar/gcc5/5.4.0/lib/gcc/5 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-5 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl014 --with-system-zlib --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc5 5.4.0' --with-bugurl=https://github.com/Homebrew/homebrew-versions/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 5.4.0 (Homebrew gcc5 5.4.0)
关于c - 将 Homebrew 编译的 openmpi(或 mpich2)链接到 Homebrew 的 gcc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26812780/