由于预处理器指令导致SWIG错误 [英] SWIG errors because of preprocessor directive

查看:59
本文介绍了由于预处理器指令导致SWIG错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一家供应商为我们提供了C ++库和标头,我正尝试使用SWIG包装它们。似乎他们对预处理器指令的理解太聪明了:

We have a vendor that has provided us a C++ library and headers, that I'm trying to wrap using SWIG. It appears that they are being too clever by a half with the preprocessor directives:

// top.h
#define DECLARE_WITH_COMMA(a) a,

,然后

// foo.h
#include "top.h"

#define MY_TYPES(d) \
  d(One)   \
  d(Two)   \
  d(Three) \
  NumElems

enum MyTypes {
  MY_TYPES(DECLARE_WITH_COMMA)
};

当我尝试运行SWIG(2.0.4版)时,这都是一种漫不经心的说法。在 foo.h上,我得到:

Which is all a longwinded way of saying that when I try to run SWIG (version 2.0.4) on "foo.h", I get:

foo.h:12: Error: Syntax error in input(1).

所以我的问题是我在这里有什么选择,因为我可能不想更改供应商提供的标题?

So my question is what are my options here, given that I probably don't want to change the vendor-supplied headers?

推荐答案

默认情况下,SWIG不会递归到嵌套标头中,因此您的 .i 文件应类似于:

SWIG doesn't recurse into nested headers by default, so your .i file should look something like:

%module mymod

%{
#include "foo.h"
%}

%include "top.h"
%include "foo.h"

还有一个SWIG开关:

There is also a SWIG switch:

-includeall     - Follow all #include statements

,但是如果系统标头的作用可能超出预期。

but if you have system headers that may do more than you intend.

这篇关于由于预处理器指令导致SWIG错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆