clang: 错误: 在Mac OSX El Capitan构建XGBoost时,不支持选项“-fopenmp”

24

我正在尝试根据这些说明,构建Python的XGBoost软件包:

以下是使用支持OpenMP编译器安装XGBoost的完整解决方案。通过brew install gcc --without-multilib获取支持openmp的gcc-5.x.x(brew是OS X上apt-get的事实标准,因此不建议单独安装HPC,但应该可以正常工作):

git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/config.mk ./config.mk; make -j4

这个错误恰好发生在make -j4命令中。

提前搜索后,我尝试了这两个解决方案(12),但都没有用,除了安装另一个gcc以免一切被搞砸的部分。

下面是make配置文件。它没有任何可疑之处。

#-----------------------------------------------------
#  xgboost: the configuration compile script
#
#  If you want to change the configuration, please use the following
#  steps. Assume you are on the root directory of xgboost.
#  First copy the this file so that any local changes will be ignored by git
#
#  $ cp make/config.mk .
#
#  Next modify the according entries, and then compile by
#
#  $ make
#
#  or build in parallel with 8 threads
#
#  $ make -j8
#----------------------------------------------------

# choice of compiler, by default use system preference.
# export CC = gcc
# export CXX = g++
# export MPICXX = mpicxx

# the additional link flags you want to add
ADD_LDFLAGS =

# the additional compile flags you want to add
ADD_CFLAGS =

# Whether enable openmp support, needed for multi-threading.
USE_OPENMP = 1

# whether use HDFS support during compile
USE_HDFS = 0

# whether use AWS S3 support during compile
USE_S3 = 0

# whether use Azure blob support during compile
USE_AZURE = 0

# Rabit library version,
# - librabit.a Normal distributed version.
# - librabit_empty.a Non distributed mock version,
LIB_RABIT = librabit.a

# path to libjvm.so
LIBJVM=$(JAVA_HOME)/jre/lib/amd64/server

# List of additional plugins, checkout plugin folder.
# uncomment the following lines to include these plugins
# you can also add your own plugin like this
#
# XGB_PLUGINS += plugin/example/plugin.mk

1
请仔细阅读 Makefile 中的注释。 - user707650
4个回答

34

你使用Homebrew安装了gcc,但错误来自clang。这意味着你的默认编译器仍然指向clang而不是新安装的gcc。如果你阅读Makefile中的注释,你会看到以下几行:

# choice of compiler, by default use system preference.
# export CC = gcc
# export CXX = g++
# export MPICXX = mpicxx

在你的情况下,你不想要系统自带的。
注意:gcc 对于系统指向 clang

$ which gcc
/usr/bin/gcc
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.29)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

相反,将这些变量指向/usr/local/bin中的某个内容,例如:

$ export CC=/usr/local/bin/gcc

对于另外两个变量CXXMPICXX同样如此,例如:

$ export CC=/usr/local/bin/gcc;CXX=/usr/local/bin/g++;MPICXX=/usr/local/bin/mpicxx

在我的系统中,命令 which gcc 给出了这个结果:/usr/bin/gcc。然后我在终端中运行了命令:export CC=/usr/bin/gcc。但错误仍然存在。我对 gccmake 等方面并不是很专业。 - srodriguex
3
尝试运行命令ls /usr/local/bin/gcc*,我认为结果会是gcc-5或类似的内容。您需要将其与上面的export CC=...一起使用。 - Mark Setchell
1
ls /usr/local/bin/gcc* 给我列出了一系列链接,其中一个以 gcc-5 结尾。然后我运行命令 export CC=/usr/local/bin/gcc-5。我还将此命令放入 make 文件配置中,但没有成功。 :( - srodriguex
1
嘿!命令 echo $CC 给了我原始的 /usr/bin/gcc。但是单独执行 export 命令的结果给了我一堆声明,其中一个变量 CC 正确地指向 /usr/local/bin/gcc-5。到底发生了什么? - srodriguex
2
@srodriguex 注意:其他两个变量也类似。还需定义CXX和MPICXX。 - user707650
这个救了我的命。 - Ayan Mitra

9
先生,也许您应该使用以下命令:

cd xgboost; cp make/minimum.mk ./config.mk; make -j4

而不是根据“在OSX上构建”部分的说明使用以下命令:

cd xgboost; cp make/config.mk ./config.mk; make -j4

请参阅构建文档

3
按照被接受的答案操作后,问题对我来说已经解决了。 - lagrange103
1
这对我也起作用了,但在执行上面写的第一步之后,谢谢。 - Vipin Chaudhary
是的,你必须先更改输出,我想知道这是个错误还是与其他事情有关。 - Sahan Jayasumana

3
为了解决这个问题,我采取了以下步骤:我意识到我已经安装了gcc 6,所以我运行了以下命令:
export CC=gcc-6

但是仅靠它自己不够,所以我还需要:

export CXX=g++-6

这对我解决了问题。我使用的是运行macOS Sierra的Macbook Pro。如果您愿意,您也可以直接在XGBoost的Makefile上进行这些更改。有关更多信息,请参见:https://www.ibm.com/developerworks/community/blogs/jfp/entry/Installing_XGBoost_on_Mac_OSX?lang=en


0

无法编译本地 libxgboost.dylib 库,也许可以查看此 解决方法


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接