首页 > 解决方案 > Cython 编译警告不兼容类型

问题描述

我正在尝试在 cython 中使用 ac DLL,在编译阶段我收到了来自 C 编译器的警告:

warning C4133: "=" : incompatible types - from 'foobar *' to 'foobar *'.

我的 pxd 看起来像这样:

#!/usr/bin/env python3
#cython: language_level=3

cdef extern from "typedef.h"
    struct foobar:
        long *index
        double *my_array
        int value

cdef extern from "functions.h"
    
    foobar *get_foobar(char *name);

我的 pyx 就是这样:

cimport pxd_file_name

cdef class Handler:
    cdef pxd_file_name.foobar *__foobar

    def load_foobar(self, char *name):
        self.__foobar = pxd_file_name.get_foobar(name) <==

    def another_method(self):
        pass

由于箭头标记的线,我收到了警告,但我不明白为什么。

有没有办法来解决这个问题 ?

标签: cython

解决方案


我设法找到了我的错误。

因为在我的 .h 文件中,我的结构是使用 typedef 声明的,所以我必须写ctypedef struct foobar而不是struct foobar在我的 pxd 文件中


推荐阅读