c - 如何为 SWIG 创建接口(interface)文件

标签 c swig

我有以下头文件: gaiageo.h 定义为

#ifndef DOXYGEN_SHOULD_SKIP_THIS
/* stdio.h included for FILE objects. */
#include <stdio.h>
#ifdef DLL_EXPORT
#define GAIAGEO_DECLARE __declspec(dllexport)
#else
#define GAIAGEO_DECLARE extern
#endif
#endif

#ifndef _GAIAGEO_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define _GAIAGEO_H
#endif

#include "gg_const.h"
#include "gg_structs.h"
#include "gg_core.h"
#include "gg_mbr.h"
#include "gg_formats.h"
#include "gg_dynamic.h"
#include "gg_advanced.h"

#endif /* _GAIAGEO_H */

包含的头文件充满了 GAIAGEO_DECLARE,因为 实例 gg_formats.h(这是非常典型的包含 header )具有以下内容:

/**
\file gg_formats.h

Geometry handling functions: formats
*/

#ifndef _GG_FORMATS_H
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#define _GG_FORMATS_H
#endif

#ifdef __cplusplus
extern "C"
{
#endif

/* function prototypes */

/**
 Test CPU endianness

 \return 0 if big-endian: any other value if little-endian
 */
    GAIAGEO_DECLARE int gaiaEndianArch (void);

/**
 Import an INT-16 value in endian-aware fashion

 \param p endian-dependent representation (input buffer).
 \param little_endian 0 if the input buffer is big-endian: any other value
 for little-endian.
 \param little_endian_arch the value returned by gaiaEndianArch()

 \return the internal SHORT value 

 \sa gaiaEndianArch, gaiaExport16

 \note you are expected to pass an input buffer corresponding to an
 allocation size of (at least) 2 bytes.
 */
    GAIAGEO_DECLARE short gaiaImport16 (const unsigned char *p,
                    int little_endian,
                    int little_endian_arch);
#ifdef __cplusplus
}
#endif

#endif  /* _GG_FORMATS_H */

这是我第一次尝试创建接口(interface)文件,需要一些帮助,在线文档让我感到困惑?

我应该为每个 header 创建一个接口(interface)文件吗?我应该如何为包含的 gaiageo.h 创建接口(interface)?

最佳答案

这应该可以帮助您入门,但很难确切知道您需要什么。

%include <windows.i>使 SWIG 处理窗口主义,如 __declspec(dllexport) .

默认情况下,SWIG 不会递归包含文件,因此请包含您需要 SWIG 处理的文件。有一个递归开关,但它会处理 stdio.h .

%module gaiageo

%{
#include "gaiageo.h"
%}

%include <windows.i>
%include "gaiageo.h"
%include "gg_const.h"
%include "gg_structs.h"
%include "gg_core.h"
%include "gg_mbr.h"
%include "gg_formats.h"
%include "gg_dynamic.h"
%include "gg_advanced.h"

将其另存为 gaiageo.i文件并运行类似:

swig -c++ -<target_language> gaiageo.i

关于c - 如何为 SWIG 创建接口(interface)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12723660/

相关文章:

c - 尝试添加可选规则时,在 Bison 中转移/减少冲突

java - Clojure/QuantLib 互操作 : classloading woes

python - 如何在 Python 中为类类型应用 SWIG OUTPUT 类型映射?

带有分割定义的 Cython 编译

c - 如何配置此错误以能够正确生成Makefile?

python - 在 Windows : function not found 上使用 ctypes 在 python 中包装 c++ 函数

用于读取可变参数长度的 Python C 包装器

java - 使用 Java 版 SWIG,如何有选择地获取巨大 C/C++ 头文件的某些部分?

c - Varnish C VRT变量/功能

c++ - 适当的散列函数来散列随机二进制字符串