在Mac上安装xgboost - ld:找不到库

时间:2016-03-16 14:39:07

标签: xcode macos makefile clang xgboost

我正在尝试在我的mac上安装支持OpenMP的xgboost。我安装了gcc没问题:

brew install gcc --without-multilib

然后克隆了git repository:

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

但是当我这样做时出现错误

make -j4

这是我得到的错误。如果你能帮助解决这个问题,我将不胜感激:

c++ -std=c++0x -Wall -O3 -msse2  -Wno-unknown-pragmas -funroll-loops -Iinclude   -Idmlc-core/include -Irabit/include -fPIC -fopenmp -o xgboost  build/cli_main.o build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a  -pthread -lm  -fopenmp 
c++ -std=c++0x -Wall -O3 -msse2  -Wno-unknown-pragmas -funroll-loops -Iinclude   -Idmlc-core/include -Irabit/include -fPIC -fopenmp -shared -o lib/libxgboost.so build/learner.o build/logging.o build/c_api/c_api.o build/c_api/c_api_error.o build/common/common.o build/data/data.o build/data/simple_csr_source.o build/data/simple_dmatrix.o build/data/sparse_page_dmatrix.o build/data/sparse_page_raw_format.o build/data/sparse_page_source.o build/data/sparse_page_writer.o build/gbm/gblinear.o build/gbm/gbm.o build/gbm/gbtree.o build/metric/elementwise_metric.o build/metric/metric.o build/metric/multiclass_metric.o build/metric/rank_metric.o build/objective/multiclass_obj.o build/objective/objective.o build/objective/rank_obj.o build/objective/regression_obj.o build/tree/tree_model.o build/tree/tree_updater.o build/tree/updater_colmaker.o build/tree/updater_histmaker.o build/tree/updater_prune.o build/tree/updater_refresh.o build/tree/updater_skmaker.o build/tree/updater_sync.o dmlc-core/libdmlc.a rabit/lib/librabit.a -pthread -lm  -fopenmp 
clangclang: : warningwarning: : argument unused during compilation: '-pthread'argument unused during compilation: '-pthread'

ld: library not found for -lgomp
ld: library not found for -lgomp
clang: error: clanglinker command failed with exit code 1 (use -v to see invocation): 
error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [lib/libxgboost.so] Error 1
make: *** Waiting for unfinished jobs....
make: *** [xgboost] Error 1

2 个答案:

答案 0 :(得分:1)

新版本的OSX将Clang作为默认的c \ c ++编译器。因此,c++命令引用clang++

您应该为make命令定义CC \ CXX环境变​​量,例如CC=gcc CXX=g++ make -j

此外,您可以为clang OpenMPrt构建一个OpenMP并自定义您的shell环境(我没有自己尝试)

(此时我没有mac来检查这个解决方案;只是linux)

答案 1 :(得分:1)

我有同样的问题并通过以下方式解决:

brew install clang-omp
export CC=clang-omp
export CXX=clang-omp++
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/config.mk ./config.mk; make -j4
cd python-package
sudo python setup.py install

如果您之前使用pip安装xgboost,则从项目中删除以前安装的xgboost。然后使用

pip install xgboost 

再次安装。