我是Homebrew的新手(我通常使用Macports,但是我正在第二台计算机上试用Homebrew),并且希望安装openmpi(或mpich2)软件包。步骤如下(在安装了Xcode 6的Mac OS X Yosemite上执行):
brew install gcc
brew install openmpi
但是,由于以下原因,我怀疑链接可能未正确完成:
$ 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.
$ 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编译其软件包了? 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/