When I try to test a Python module created with Cython with Travis CI, the installation looks like the following. It was.
$ python setup.py build install
running build
running build_ext
building 'neologdn' extension
creating build
creating build/temp.linux-x86_64-2.6
gcc -pthread -fno-strict-aliasing -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/opt/python/2.6.9/include/python2.6 -c neologdn.cpp -o build/temp.linux-x86_64-2.6/neologdn.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
In file included from /usr/include/c++/4.6/unordered_map:35:0,
from neologdn.cpp:255:
/usr/include/c++/4.6/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
neologdn.cpp:663:8: error: ‘unordered_map’ in namespace ‘std’ does not name a type
neologdn.cpp:666:8: error: ‘unordered_set’ in namespace ‘std’ does not name a type
This is due to the lack of std :: unordered_map
and std :: unordered_set
because the gcc version (4.6) of Travis CI is old and not compatible with C ++ 11.
Let's upgrade gcc and g ++ with .travis.yml
and set CFLAGS
.
install:
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get install -qq gcc-4.8
- sudo apt-get install -qq g++-4.8
- export CC="gcc-4.8"
- export CXX="g++-4.8"
- export CFLAGS=-std=c++11
- export CXXFLAGS=-std=c++11
- python setup.py build install
And if you explicitly specify C ++ 11 in setup.py
, everyone will be happy, not just Travis.
setup(
...
ext_modules=[Extension('hoge', ['hoge.cpp'], language='c++', extra_compile_args=["-std=c++11"])],
...
Alternatively, you can specify in Cython that ʻunordered_map is in
tr1`, as shown below.
# from https://github.com/ikuyamada/cython-cpp-experiment/blob/master/unordered_map.pxd
from libcpp.utility cimport pair
cdef extern from "<tr1/unordered_map>" namespace "std::tr1":
cdef cppclass unordered_map[T, U]:
cppclass iterator:
pair[T, U]& operator*() nogil
iterator operator++() nogil
iterator operator--() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
unordered_map()
unordered_map(unordered_map&)
U& operator[](T&) nogil
# unordered_map& operator=(unordered_map&)
U& at(T&) nogil
iterator begin() nogil
void clear() nogil
size_t count(T&) nogil
bint empty() nogil
iterator end() nogil
pair[iterator, iterator] equal_range(T&) nogil
void erase(iterator) nogil
void erase(iterator, iterator) nogil
size_t erase(T&) nogil
iterator find(T&) nogil
pair[iterator, bint] insert(pair[T, U]) nogil
iterator insert(iterator, pair[T, U]) nogil
void insert(input_iterator, input_iterator)
size_t max_size() nogil
void rehash(size_t)
size_t size() nogil
void swap(unordered_map&) nogil
Recommended Posts