SWIG 如何选择退出整个界面并仅包装一个功能

问题描述 投票:0回答:1

假设我的 A 类看起来像这样:

class A {
public:
 A() = defualt;
 ~A() = defualt;

 void foo();
 void bar();
 void baz();
 void qux();
};

我想创建该类的包装器,但我只需要使用函数

foo
。 我知道我可以使用

%ignore A::bar;
%ignore A::baz;
%ignore A::qux;

为了避免包装其余的函数,但请看一下写作,如果有人要添加新函数,他将不得不添加新的

ignore

SWIG 选项中是否有选择退出类的整个接口并仅告诉我要包装哪个函数?

c++ swig
1个回答
0
投票

SWIG 仅包装您告诉它的内容,因此在 interface(.i) 文件中,使用类似以下内容:

%module test

%{
#include "A.h"    // Needed to build the wrapper
%}

// Only declare what you want to wrap instead of %include the whole header.
class A {
public:
    A() = default;
    ~A() = default;
    void foo();
};

现在如果其他函数添加到包含文件中,它们将不会被包装。

© www.soinside.com 2019 - 2024. All rights reserved.