LoginSignup
2
1

More than 5 years have passed since last update.

Macでsetup.pyから拡張モジュールをコンパイルする時にgccを使う方法

Posted at

C++のコードをswigを使ってbindingする際に、setup.pyを使ってshared objectを作る。
Mac OS Xでやろうとすると、ライブラリ自体はg++でコンパイルされているのに、Clangでコンパイルしようとしてエラーをはいてしまう。

こんな感じ。

$ python setup.py build_ext             
running build_ext
building '_Mykytea' extension
cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -I/usr/local/include -I/usr/local/opt/sqlite/include -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c mykytea_wrap.cxx -o build/temp.macosx-10.8-intel-2.7/mykytea_wrap.o
(略)
In file included from mykytea_wrap.cxx:3481:
In file included from ./mykytea.hpp:9:
/usr/local/include/kytea/kytea.h:128:24: error: implicit instantiation of undefined template
      'kytea::Dictionary<kytea::ModelTagEntry>'
        if(dict_ != 0) delete dict_;
                       ^
/usr/local/include/kytea/kytea.h:34:26: note: template is declared here
template <class T> class Dictionary;
                         ^
2 warnings and 1 error generated.
error: command 'cc' failed with exit status 1

で、呼んでもいないClangはほっといてgccでコンパイルするには、

 $ ARCHFLAGS="-arch x86_64" CC=gcc CXX=g++ python setup.py build_ext

とすればよい。

本当はsetup.pyに書く方法のが良いのかもしれないけど、オリジナルのライブラリが何でコンパイルされたかを、動的に判断するのってできるのかなぁ。

というわけで、めでたくKyteaのPythonバインディングが最新の0.4.4に対応しました。

2
1
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
2
1