简体   繁体   English

使用SWIG包装octave的C ++ API

[英]wrapping octave's C++ API using SWIG

What is the best way to wrap octave's C++ API using SWIG? 使用SWIG包装octave的C ++ API的最佳方法是什么?

All I would need would be the interface file (something like wrap_octave.i), which could be used to generate wrappers for another language (D in my case, but it shouldn't matter). 我需要的只是接口文件(类似于wrap_octave.i),它可以用来生成另一种语言的包装器(在我的情况下为D,但它应该无关紧要)。

I can get wrap individual functions by writing them explicitly in the interface file but this is laborious. 我可以通过在接口文件中明确地编写它们来包装单个函数,但这很费力。 If I %include header files in the interface file it is not clear which ones to include without generating compiler errors. 如果I%在接口文件中包含头文件,则不清楚要包含哪些头文件而不生成编译器错误。 NOTE: the target language for the wrapper is NOT octave; 注意:包装器的目标语言不是八度音; instead I want to use embedded octave in another language via the C++ api. 相反,我想通过C ++ api在另一种语言中使用嵌入式八度音程。

I'm not exactly sure what you want, but SWIG doesn't offer easy shortcuts like "don't wrap anything that isn't supported". 我不确定你想要什么,但SWIG不提供简单的快捷方式,例如“不要包装任何不受支持的东西”。 It doesn't %include recursively, which is generally good to avoid wrapping stuff you don't want, but it means you need to manage the %include order manually. 它不包括递归,这通常很好地避免包装你不想要的东西,但这意味着你需要手动管理%include命令。 If you provide dependencies in the wrong order, SWIG may generate incorrect code without emitting error or warning messages. 如果以错误的顺序提供依赖项,SWIG可能会生成错误的代码而不会发出错误或警告消息。

In my library I have control of the header files, so I can easily exclude stuff I don't want, eg 在我的库中,我控制了头文件,因此我可以轻松地排除我不想要的东西,例如

#ifdef SWIG
#define INTERNAL protected
#else
#define INTERNAL public
#endif

class Foo {
public:
    void Bar();
INTERNAL: // hide from SWIG
    void Baz();
};

So one option is to duplicate the headers and modify them until they are suitable for SWIG, or just strip out everything you don't want to wrap. 因此,一种选择是复制标题并修改它们直到它们适合SWIG,或者只删除您不想包装的所有内容。 In many cases you can also %include the headers unmodified, and %ignore the classes and functions you don't want. 在许多情况下,您还可以%包含未修改的标头,%忽略您不想要的类和功能。

If you want special treatment for some data types, expect to get your hands dirty with typemaps. 如果您需要对某些数据类型进行特殊处理,那么您可能会想要使用类型图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM