tags:

views:

333

answers:

1

I have C 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

+1  A: 

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>
Jackson