[英]swig cannot wrap exported c++ file into python
我正在使用swig
将 c++ 包装到 python 中。
我的PackA.h
是:
#ifndef PACKA_HEADER_H
#define PACKA_HEADER_H
#include <string>
class PackA
{
public:
PackA();
};
#endif
我的PackA.i
是:
%module PackA
%{
#define SWIG_FILE_WITH_INIT
#include "PackA.h"
%}
%include "PackA.h"
它成功生成了python模块。
但是,如果我通过以下方式将PackA
声明为 dll:
// #include "PackAGlobal.h"
#ifndef PACKA_EXPORTES_H
#define PACKA_EXPORTES_H
#if (WIN32)
#ifdef PackA_EXPORTS
#define PackA_EXPORT __declspec(dllexport)
#else
#define PackA_EXPORT __declspec(dllimport)
#endif
#else
#define PackA_EXPORT
#endif
#endif
// PackA.h
#ifndef PACKA_HEADER_H
#define PACKA_HEADER_H
#include "PackAGlobal.h"
#include <string>
class PackA
{
public:
PackA();
};
#endif
VS 报告错误:
c4430 missing type specifier - int assumed. note c++ does not support default-int
c2071 abstract declarator illegal storage class
c2513: PackA: no variable declared before =
如何将此导出类包装到 python 中?
更新 - - - - - - - - - - - - - - - - - - - - - - - - - ----------
感谢@Mark Tolonen 的建议。
我将我的PackA.i
修改为:
%module PackA
%{
#define SWIG_FILE_WITH_INIT
#include "PackA.h"
%}
%include <windows.i>
%include "PackA.h"
但是,该错误仍然存在。
我已经将示例代码上传到了github: https ://github.com/zhang-qiang-github/SwigTest
终于找到了解决办法,我已经把正确的代码上传到了github: https ://github.com/zhang-qiang-github/SwigTest。 希望它可以帮助某人。
解决方案是:
PackA.i
中添加%include "PackAGlobal.h"
。PackAWrapping
PackA_EXPORTS
SET_TARGET_PROPERTIES(PackAWrapping
PROPERTIES
COMPILE_DEFINITIONS PackA_EXPORTS
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.