Wrapping C structs with SWIG

﹥>﹥吖頭↗ 提交于 2019-12-11 07:17:42

问题


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:


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>


来源:https://stackoverflow.com/questions/1700717/wrapping-c-structs-with-swig

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!