吾编译代码,尽可能要求去掉警告.今天编译注意到有这样一个:
In file included from /usr/include/python2.7/numpy/ndarraytypes.h:1777:0, from /usr/include/python2.7/numpy/ndarrayobject.h:18, from /usr/include/python2.7/numpy/arrayobject.h:4, from gh_python.h:30, from gh_python.cpp:1: /usr/include/python2.7/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp] #warning "Using deprecated NumPy API, disable it by " \
这个警告到处都有,应该去掉,这样编译时很清爽.先从网上搜索了一下,没找到有效的解决办法(都说是要安装什么,安装了其实没用).怎么办?
吾打开ndarraytypes.h:
/* * Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files * npy_*_*_deprecated_api.h are only included from here and nowhere else. */ #ifdef NPY_DEPRECATED_INCLUDES #error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES." #endif #define NPY_DEPRECATED_INCLUDES #if !defined(NPY_NO_DEPRECATED_API) || \ (NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION) #include "npy_1_7_deprecated_api.h" #endif
先定义了一个NPY_DEPRECATED_INCLUDES,被警告.
于是定义了#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION,警告消失.
希望能给同样要求的朋友,带来一点帮助.
后来在github上有人问这个总是,吾提供了本博文:
https://github.com/scipy/scipy/issues/5889#issuecomment-698615330
有人回复:
Pass define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")] as an option to the distutils.extension.Extension constructor in your setup.py
吾觉得还是直接定义的好。