开发者

Wrapping C structs with SWIG

I have C开发者_JAVA技巧 header file containing the following type definition:

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

I try to wrap this struct with SWIG, but apparently I am doing something wrong. My SWIG interface file looks like

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

But if I copy the contents of my header file into my interface file so that the latter looks like

%module example

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

I can access the struct from Ruby in the following way

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

Is there a way to automatically wrap a header file? I don't want to copy and paste the contents of the header file to the interface file every time I change it.

Thanks in advance for your help.

-- t6d


It's been a while since I used Swig but as I recall %inline is used to pass through the inline part directly to the compiler; Swig itself doesn't see it, What I think you need is:

%module example
%include<example.h>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜