【发布时间】:2016-11-30 22:39:14
【问题描述】:
当我尝试调用 libjpeg 的 jpeg_create_decompress() 函数时,我得到了
/usr/include/x86_64-linux-gnu/jconfig.h:8:34: error: invalid suffix '.0' on floating constant
#define LIBJPEG_TURBO_VERSION 1.5.0
^
.../main.swift:49:5: error: use of unresolved identifier 'jpeg_create_decompress'
jpeg_create_decompress(&info)
^~~~~~~~~~~~~~~~~~~~~~
CJPEG.jpeg_CreateDecompress:1:13: note: did you mean 'jpeg_CreateDecompress'?
public func jpeg_CreateDecompress(_ cinfo: j_decompress_ptr!, _ version: Int32, _ structsize: Int)
^
<unknown>:0: error: build had 1 command failures
现在,看看里面jpeglib.h我明白了
/* Initialization of JPEG compression objects.
* jpeg_create_compress() and jpeg_create_decompress() are the exported
* names that applications should call. These expand to calls on
* jpeg_CreateCompress and jpeg_CreateDecompress with additional information
* passed for version mismatch checking.
* NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.
*/
#define jpeg_create_compress(cinfo) \
jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
(size_t) sizeof(struct jpeg_compress_struct))
#define jpeg_create_decompress(cinfo) \
jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
(size_t) sizeof(struct jpeg_decompress_struct))
EXTERN(void) jpeg_CreateCompress (j_compress_ptr cinfo, int version,
size_t structsize);
EXTERN(void) jpeg_CreateDecompress (j_decompress_ptr cinfo, int version,
size_t structsize);
jpeg_create_decompress 不可用,可能如documentation 所述:
C 和 Objective-C 中使用了复杂的宏,但在 Swift 中没有对应的宏。复杂宏是不定义常量的宏,包括带括号的、类似函数的宏。您在 C 和 Objective-C 中使用复杂的宏来避免类型检查约束或避免重新输入大量样板代码。但是,宏会使调试和重构变得困难。在 Swift 中,您可以使用函数和泛型来获得相同的结果,而不会做出任何妥协。 因此,C 和 Objective-C 源文件中的复杂宏不适用于您的 Swift 代码。
但是如果没有这个宏,我如何在 Swift 中使用libjpeg?
【问题讨论】:
标签: swift c-preprocessor libjpeg