[PYTHON] How to use gcc when compiling extension modules from setup.py on Mac

When binding C ++ code using swig, use setup.py to create a shared object. When I try to do it on Mac OS X, the library itself is compiled with g ++, but when I try to compile it with Clang, I get an error.

Like this.

$ 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
(Abbreviation)
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

So, if you don't call Clang, you can leave it alone and compile it with gcc.

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

And it is sufficient.

Actually, it may be better to write it in setup.py, but I wonder if it is possible to dynamically determine what the original library was compiled with.

So, congratulations Kytea's Python bindings is now compatible with the latest 0.4.4.

Recommended Posts

How to use gcc when compiling extension modules from setup.py on Mac
How to use SWIG from waf
How to install mysql-connector-python on mac
How to use Dataiku on Windows
Notes on how to use pywinauto
Notes on how to use featuretools
How to install OpenCV on Mac
How to use homebrew on Debian
Notes on how to use doctest
Use gcc-4.2 when compiling Python (MacOS)
Update Python on Mac from 2 to 3
How to install drobertadams / toggl-cli on Mac
[TF] How to use Tensorboard from Keras
I want to use Linux on mac
How to use Google Assistant on Windows 10
How to erase Python 2.x on Mac.
Memorandum on how to use gremlin python
How to read environment variables from .env file in PyCharm (on Mac)
Study from Python Hour7: How to use classes
How to use Python Kivy ④ ~ Execution on Android ~
When I try to use Jupiter notebook on Mac, I can only select python2
Use Tor to connect from urllib2 [Python] [Mac]
How to pass arguments when invoking python script from blender on the command line
Preparing to use aws cli on Mac OS X
How to use Keras ~ From simple model generation to CNN ~
[Ansible] How to use SSH password authentication when executing ansible
How to use C216 Audio Controller on Arch Linux
Memo of how to use properly when combining pandas.DataFrame
Preferences to generate animated GIFs from Python on Mac
How to use Azure Table storage from Django (PTVS)
A memorandum on how to use keras.preprocessing.image in Keras
How to use TensorFlow on GPUs less than Titan
How to exit when using Python in Terminal (Mac)
Autoencoder with Chainer (Notes on how to use + trainer)
How to use Django on Google App Engine / Python
[Tips] How to use iPhone as webcam on Linux
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []