17

在编译一堆与 Numpy 接口的 Cython 生成的 C 文件时,我收到警告:

/usr/lib/pymodules/python2.7/numpy/core/include/numpy/__ufunc_api.h:226:1: warning: ‘_import_umath’ defined but not used [-Wunused-function]

我似乎无法摆脱它。认为这可能类似于np.import_array(),它消除了相关警告(实际上是使用 Numpy C API 所必需np.import_umath()的),我在顶层尝试过,但警告仍然存在。我该如何摆脱它?

(Cython 0.17.4,Numpy 1.6.2。)

4

2 回答 2

5

There's a thread on the Cython mailing list that discusses this a little bit. I believe that the discussion was concerning the Cython test suite, but I think the same ideas can be applied to generated files.

In essence, the issue involved a hack that was done in order to avoid C compiler warnings about unused functions.

The code file in question currently looks like this:

cdef extern from *:
   bint FALSE "0"
   void import_array()
#   void import_umath()

if FALSE:
    import_array()
#    import_umath()

In the past, the import_umath() portions were uncommented, but as it turns out, this was causing errors when building in C++ mode. So it appears that it was decided that a compiler warning is much better than a broken build.

In short, it seems this particular warning exists for the sake of C++ compatibility, and can be safely ignored. I suppose if you really dislike it, and if you're building in C mode, then you could try to do the same hack, by importing a similar .pxi file with a call to import_umath() inside of your Cython code.

于 2013-05-06T16:36:29.047 回答
0

好吧,它说的是代码中有一个函数,它已声明但未使用,因此它可能已过时且不应该存在。因为它只是一个警告,而且不是很危险(除非你会留下很多这样的功能,破坏代码,增加内存使用,二进制大小等等)我会简单地忽略它 - 很可能它不值得你花时间;)

于 2013-01-18T13:51:40.867 回答