LoginSignup
9
7

More than 3 years have passed since last update.

macでライブラリをビルドしてインストールするときはbinutilsに気をつける

Last updated at Posted at 2018-12-06

TL; DR

macで静的ライブラリのリンクエラーが発生するときは静的ライブラリの生成に使われている ar / ranlib がbinutilsのものになっていないか注意したほうが良いという話。

事象

mac環境へXGBoostをインストールしようと pip3.7 install xgboost を実行したところエラーが発生してインストールに失敗する事象に遭遇しました。

環境

環境 バージョン
macOS 10.14.1
Python 3.7.1
pip 18.1
XGboost 0.81

エラーメッセージ

エラーメッセージを眺めてみるとどうも静的ライブラリのリンクに失敗しているようです。

$ pip3.7 install --user -U xgboost
...
    ld: warning: ignoring file rabit/lib/librabit.a, file was built for archive which is not the architecture being linked (x86_64): rabit/lib/librabit.a
    Undefined symbols for architecture x86_64:
     "_RabitLinkTag", referenced from:
          __GLOBAL__sub_I_c_api.cc in c_api.o
      "rabit::engine::Allreduce_(void*, unsigned long, unsigned long, void (*)(void const*, void*, int, MPI::Datatype const&), rabit::engine::mpi::DataType, rabit::engine::mpi::OpType, void (*)(void*), void*)", referenced from:
          xgboost::LearnerImpl::LazyInitModel()      in learner.o
...

調査

手動でビルドして確認

XGBoost-0.81のtarballをダウンロードして手元で順々にビルドをして調査を行いましたがリンクしようとしている静的ライブラリはちゃんと生成されていてなぜエラーが発生するのか謎は深まるばかりでした。

$ cd xgboost-0.81/xgboost/rabit
$ make && ls rabit/lib
README.md  librabit.a  librabit.so  librabit_base.a  librabit_mock.a  librabit_mock.so
$ file rabit/lib/librabit.a
rabit/lib/librabit.a: current ar archive

ググってみたら

途方にくれながらググってみたら同じような事象に遭遇している方のブログを発見しました。

記事の通り ar コマンドを確認してみると自分の環境も確かにbinutilsの arranlib が使用されているようでした。

$ which ar
/usr/local/bin/ar
$ ar V
GNU ar (GNU Binutils) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

$ which ranlib
/usr/local/bin/ranlib
$ ranlib -v
GNU ranlib (GNU Binutils) 2.31.1
Copyright (C) 2018 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

そして解決

そこで発見したブログ記事と同じように /usr/bin にインストールされている arranlib を使うようにしてみたところ問題解決。
無事にXGBoostをインストールすることができるようになったのでした。

$ which ar; which ranlib
/usr/bin/ar
/usr/bin/ranlib
$ pip3.7 install --user -U xgboost
Collecting xgboost
  Downloading https://files.pythonhosted.org/packages/4f/4c/4969b10939c4557ae46e5569d07c0c7ce772b3d6b9c1401a6ed07059fdee/xgboost-0.81.tar.gz (636kB)
    100% |████████████████████████████████| 645kB 4.4MB/s
Requirement already satisfied, skipping upgrade: numpy in ./Library/Python/3.7/lib/python/site-packages (from xgboost) (1.15.2)
Requirement already satisfied, skipping upgrade: scipy in ./Library/Python/3.7/lib/python/site-packages (from xgboost) (1.1.0)
Installing collected packages: xgboost
  Running setup.py install for xgboost ... done
Successfully installed xgboost-0.81

まさかbinutilsが原因になっているとは思いもよりませんでした。
やっぱりmacをLinuxと同じように使うのは辛いのだな……。

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7