我正在尝试为一个库生成一个 swig 接口(interface),该库具有一个继承自 std::exception
的类。我似乎无法让它工作。
这是一个简单的例子。 mylib.h
的代码:
#pragma once
#include <exception>
class CustomException : public std::exception
{
};
这是 mylib.i
的代码:
%module mylib
%{
#include "mylib.h"
%}
/*
Run without anything:
mylib.h:5: Warning 401: Nothing known about base class 'std::exception'. Ignored.
*/
/*
Run with: %include <exception>
mylib.i:11: Error: Unable to find 'exception'
*/
/*
Run with: %include exception.i
mylib.h:5: Warning 401: Nothing known about base class 'std::exception'. Ignored.
*/
%include "mylib.h"
正如您在 mylib.i
中的评论中看到的那样,swig 似乎很难弄清楚 std::exception
是什么。
最佳答案
使用 %include <std_except.i>
:
%module test
%include <std_except.i>
%inline %{
class CustomException : public std::exception
{
};
%}
关于c++ - 为覆盖 std::exception 的库生成 swig 接口(interface)时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53010141/