サブロウ丸

Sabrou-mal サブロウ丸

主にプログラミングと数学

Cython コンパイルエラー

Cythonのコンパイルエラー

デフォルトのgccのバージョンが古い可能性があります.

1. gccのバージョンを変える

$ls /usr/local/bin/ や $ls /usr/bin/ でインストールされているgccのバージョンを調べて, 新しそうなやつを $export CC=gccXX で指定してから実行する

2. コンパイルオプションを追加

extra_compile_args=["-std=c++11"]を追加

source = ["purupuru.cpp", "./purupuru.cpp.pyx"]

setup(
    cmdclass=dict(build_ext=build_ext),
    ext_modules=[
        Extension("purupuru.cpp", source, language="c++", extra_compile_args=["-std=c++11"])
    ],
    include_dirs=[np.get_include()],
)

cythonに幸あれ...

コンパイルエラー

hogehoge@opt-gtx:/work/hogehoge/bugbug.py
$python setup.py build_ext -i
running build_ext
cythoning ./purupuru.pyx to ./purupuru.c
/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /work/hogehoge/bugbug.py/purupuru.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
building 'purupuru' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include -I/home/hogehoge/.pyenv/versions/3.9.7/include -I/home/hogehoge/.pyenv/versions/3.9.7/include/python3.9 -c ./purupuru.c -o build/temp.linux-x86_64-3.9/./purupuru.o
In file included from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
                 from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from ./purupuru.c:620:
/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include -I/home/hogehoge/.pyenv/versions/3.9.7/include -I/home/hogehoge/.pyenv/versions/3.9.7/include/python3.9 -c _purupuru.c -o build/temp.linux-x86_64-3.9/_purupuru.o
gcc -pthread -shared -L/home/hogehoge/.pyenv/versions/3.9.7/lib -L/home/hogehoge/.pyenv/versions/3.9.7/lib build/temp.linux-x86_64-3.9/./purupuru.o build/temp.linux-x86_64-3.9/_purupuru.o -o /work/hogehoge/bugbug.py/purupuru.cpython-39-x86_64-linux-gnu.so
running build_ext
cythoning ./purupuru_2.pyx to ./purupuru_2.cpp
/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /work/hogehoge/bugbug.py/purupuru_2.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
building 'purupuru_2' extension
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include -I/home/hogehoge/.pyenv/versions/3.9.7/include -I/home/hogehoge/.pyenv/versions/3.9.7/include/python3.9 -c ./purupuru_2.cpp -o build/temp.linux-x86_64-3.9/./purupuru_2.o
In file included from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1822:0,
                 from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                 from ./purupuru_2.cpp:634:
/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
 #warning "Using deprecated NumPy API, disable it with " \
  ^
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/hogehoge/.pyenv/versions/3.9.7/lib/python3.9/site-packages/numpy/core/include -I/home/hogehoge/.pyenv/versions/3.9.7/include -I/home/hogehoge/.pyenv/versions/3.9.7/include/python3.9 -c _purupuru_2.cpp -o build/temp.linux-x86_64-3.9/_purupuru_2.o
_purupuru_2.cpp:4:93: error: ‘>>’ should be ‘> >’ within a nested template argument list
 (int bs, int n, double step[], float D[], std::vector<std::vector<float>> &thresho
                                                                        ^
_purupuru_2.cpp: In function ‘void extract_elements(int, int, double*, float*, std::vector<std::vector<float> >&)’:
_purupuru_2.cpp:18:17: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
                 auto result = std::find(tmp.begin(), tmp.end(), _k);)