1

我有包含以下类型定义的 C 头文件:

// example.h
typedef struct Vertex {
  int color;
} Vertex;

我尝试用 SWIG 包装这个结构,但显然我做错了什么。我的 SWIG 接口文件看起来像

// example.i
%module example
%inline %{
#include "example.h"
}

但是如果我将头文件的内容复制到我的接口文件中,以便后者看起来像

%module example

%inline %{
typedef struct Vertex {
  int color;
} Vertex;
%}

我可以通过以下方式从 Ruby 访问结构

irb> require 'example'
# => true
irb> Examlpe::Vertex
# => Vertex

有没有办法自动包装头文件?不想每次改头文件的时候都把头文件的内容复制粘贴到接口文件中。

在此先感谢您的帮助。

-- t6d

4

1 回答 1

3

自从我使用 Swig 已经有一段时间了,但我记得 %inline 用于将内联部分直接传递给编译器;Swig 本身看不到它,我认为您需要的是:

%module example
%include<example.h>
于 2009-11-09T13:29:41.303 回答