Quand j'essaye de tester un module Python créé avec Cython avec Travis CI, l'installation ressemble à ceci. C'était.
$ 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
La cause est qu'il n'y a pas de std :: unordered_map
ou std :: unordered_set
car la version gcc (4.6) de Travis CI est ancienne et ne prend pas en charge C ++ 11.
Mettons à jour gcc et g ++ avec .travis.yml
et définissons 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
Et si vous spécifiez explicitement C ++ 11 dans setup.py
, non seulement Travis mais tout le monde sera heureux.
setup(
...
ext_modules=[Extension('hoge', ['hoge.cpp'], language='c++', extra_compile_args=["-std=c++11"])],
...
Alternativement, vous pouvez spécifier en Cython que ʻunordered_map est dans
tr1` comme suit.
# 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