首页 > 解决方案 > 如何在 C++ 程序中使用 Pillow 库

问题描述

我正在尝试为 c 和 Pillow 图像处理库创建一个基于 Tensorflow 的 c++ 程序。不是opencv。

想要使用 Pillow 的原因是与使用 Pillow 的 python-tensorflow 项目制作相同的库环境。具体来说,opencv 和枕头之间的差异 resize() 函数的结果。

所以,当我在我的 c++ 代码中包含imaging.h 头文件时,编译器会出现如下错误。甚至包含在“extern c”循环中的头文件。

'ImagingMemoryArena': 'ImagingMemoryArena *' differs in levels of indirection from 'ImagingMemoryArena'

下面是imaging.h 文件中ImagingMemoryArena 结构代码的链接。

https://github.com/python-pillow/Pillow/blob/ff40eaa9615b0c37fd4bd4192e3a3219a5867c2b/src/libImaging/Imaging.h#L161

我认为 C 代码可以用 C++ 代码编译。所以在 .C 和 .CPP 文件中都尝试了以下代码。但只能在 C 文件中编译,而不是 CPP。

编译环境在visual studio 2017 c++项目上。

#if defined(__cplusplus)
extern "C" {
#endif

    typedef struct ImagingMemoryArena {
        int alignment;        /* Alignment in memory of each line of an image */
        int block_size;       /* Preferred block size, bytes */
        int blocks_max;       /* Maximum number of cached blocks */
        int blocks_cached;    /* Current number of blocks not associated with images */
        int stats_new_count;           /* Number of new allocated images */
        int stats_allocated_blocks;    /* Number of allocated blocks */
        int stats_reused_blocks;       /* Number of blocks which were retrieved from a pool */
        int stats_reallocated_blocks;  /* Number of blocks which were actually reallocated after retrieving */
        int stats_freed_blocks;        /* Number of freed blocks */
    } *ImagingMemoryArena;

#if defined(__cplusplus)
}
#endif

我想知道原因,为什么 c++ 编译器会对上述代码产生错误,甚至包括“extern C”。谢谢。

标签: c++cvisual-studio-2017python-imaging-library

解决方案


推荐阅读