带有swig-to-python模块的c++类
c++ classes with swig to python module
我需要将此类c++转换为python模块,并给出错误/*arexcrypt.h*/
#ifndef AREXCRYPT_H
#define AREXCRYPT_H
//Qt
#include <QString>
#include <QVector>
#include <QFlags>
//App
#include "singleton.h"
class ArexCrypt: public Singleton<ArexCrypt>
{
friend class Singleton<ArexCrypt>;
public:
enum Compression {
IfReducedCompress,
AlwaysCompress,
NeverCompress
};
enum IntegrityCheck {
NoCheck,
ChecksumCheck,
HashCheck
};
enum Error {
NoneError,
NoKeyError,
NoDataError,
UnknownVersionError,
IntegrityError
};
enum CryptoFlag{
NoneFlag = 0,
CompressedFlag = 0x01,
ChecksumFlag = 0x02,
HashFlag = 0x04
};
Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag);
void setKey(quint64 pKey);
Compression CompressionMode() const;
void setCompressionMode(Compression pMode);
IntegrityCheck IntegrityProtectionMode() const;
void setIntegrityProtectionMode(IntegrityCheck pMode);
Error LastError() const;
//METHODS
QString EncryptToString(const QString &pText);
QString DecryptToString(const QString &pEncryptedText);
QString GenerateIntegrityKey(const QString &pText);
bool CheckIntegrityKey(const QString &pText);
private:
//Data
quint64 key;
QVector<char> keyParts;
Compression compressionMode;
IntegrityCheck protectionMode;
Error lastError;
bool showConsoleMessages;
//CONTRUCTORS AND DESTROYERS
ArexCrypt();
//METHODS
void SplitKey();
void EncryptArray(QByteArray &pArray);
void DecryptArray(QByteArray &pArray);
QByteArray GenerateIntegrityData(QByteArray dataArray, CryptoFlags &flags);
QByteArray EncryptToByteArray(QByteArray pTextArray);
QByteArray DecryptToByteArray(QByteArray pEncryptedArray);
//OTHERS
QString EncryptToString(QByteArray pTextArray);
QString DecryptToString(QByteArray pEncryptedArray);
QByteArray EncryptToByteArray(const QString &pText);
QByteArray DecryptToByteArray(const QString &pEncryptedText);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ArexCrypt::CryptoFlags);
#endif // AREXCRYPT_H
/arexcrypt.i/
/* arexcrypt.i */
%module arexcrypt
%{
#include "arexcrypt.h"
%}
%import "singleton.i"
%include std_string.i
%include std_vector.i
%include stl.i
%include "arexcrypt.h"
/*singleton.h*/
#ifndef SINGLETON_H
#define SINGLETON_H
template <typename T> struct Singleton
{
static T &instance()
{
static T m_instance;
return m_instance;
}
protected:
Singleton() { }
};
#endif // SINGLETON_H
/*singleton.i*/
/* singleton.i */
%module singleton
%{
#include "singleton.h"
%}
%include "singleton.h"
%template(intSingleton) Singleton<int>;
然后当我转换为python时,我会在控制台上得到这个
swig-c++-python arexcrypt.i
arexcrypt.h(11):警告401:对基类"Singleton<ArexCrypt>'。已忽略。arexcrypt.h(11):警告401:也许您忘记实例化"Singleton<ArexCrypt>'正在使用%template。arexcrypt.h(40):警告504:函数arexcrypt::Q_DECLARE_FLAGS(CryptoFlags,arexcrypt::CryptoFlag)必须具有返回类型。已忽略。arexcrypt.h(81):警告503:除非重命名为有效标识符,否则无法包装"arexcrypt::CryptoFlags"。
gcc-c arexcrypt_wrap.cxx-o arexcrypt.o-fpic-std=c++0x
我有这个
arexcrypt_wrap.cxx:1: warning: -fpic ignored for target (all code is position independent)
arexcrypt_wrap.cxx:171:21: error: Python.h: No such file or directory
arexcrypt_wrap.cxx:3027:4: error: #error "This python version requires swig to be run with the '-classic' option"
In file included from arexcrypt_wrap.cxx:3124:
arexcrypt.h:5:19: error: QString: No such file or directory
arexcrypt.h:6:19: error: QVector: No such file or directory
arexcrypt.h:7:18: error: QFlags: No such file or directory
arexcrypt_wrap.cxx:801: error: 'PyObject' was not declared in this scope
arexcrypt_wrap.cxx:801: error: 'str' was not declared in this scope
arexcrypt_wrap.cxx:802: error: expected ',' or ';' before '{' token
arexcrypt_wrap.cxx:825: error: expected initializer before '*' token
arexcrypt_wrap.cxx:851: error: expected initializer before '*' token
arexcrypt_wrap.cxx:905: error: expected initializer before '*' token
arexcrypt_wrap.cxx:920: error: 'inquiry' does not name a type
arexcrypt_wrap.cxx:921: error: 'intargfunc' does not name a type
arexcrypt_wrap.cxx:922: error: 'intintargfunc' does not name a type
arexcrypt_wrap.cxx:923: error: 'intobjargproc' does not name a type
arexcrypt_wrap.cxx:924: error: 'intintobjargproc' does not name a type
arexcrypt_wrap.cxx:925: error: 'getreadbufferproc' does not name a type
arexcrypt_wrap.cxx:926: error: 'getwritebufferproc' does not name a type
arexcrypt_wrap.cxx:927: error: 'getsegcountproc' does not name a type
arexcrypt_wrap.cxx:928: error: 'getcharbufferproc' does not name a type
arexcrypt_wrap.cxx:929: error: 'PyObject' was not declared in this scope
arexcrypt_wrap.cxx:929: error: 'x' was not declared in this scope
arexcrypt_wrap.cxx:929: error: expected primary-expression before 'void'
arexcrypt_wrap.cxx:929: error: initializer expression list treated as compound expression
arexcrypt_wrap.cxx:930: error: expected ',' or ';' before '{' token
In file included from c:mingw64_4.4.6bin../lib/gcc/x86_64-w64-mingw32/4.4.6/../../../../x86_64-w64-mingw32/include/c++/4.4.6/stdexcept:38,
from arexcrypt_wrap.cxx:3051:
c:mingw64_4.4.6bin../lib/gcc/x86_64-w64-mingw32/4.4.6/../../../../x86_64-w64-mingw32/include/c++/4.4.6/exception:35: error: expected declaration before end of line
任何人都知道可能发生了什么我做错了
作为一条规则:始终查看第一个错误,这可能是罪魁祸首。
在您的情况下
arexcrypt_wrap.cxx:1: warning: -fpic ignored for target (all code is position independent)
arexcrypt_wrap.cxx:171:21: error: Python.h: No such file or directory
您缺少python开发文件。
相关文章:
- 尝试导入pybind-opencv模块时出现libgtk错误
- 为什么当我解模块化时,这个C++代代码"效率较低"?
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 内联如何影响模块接口中的成员函数
- C++返回 Numpy 数组的 Python 扩展模块
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 如何从线程中的不同模块调用函数?
- 如何使用 soong 命名空间来有条件地编译模块
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- CMake - 模块 + 库混淆
- 特征 LLT 模块给出不正确的结果?
- 枚举进程模块在有效句柄上返回无效句柄
- 在 python 模块中导入子模块时PyImport_Import失败
- 将 PCL 链接到 Cython C++ 模块
- 即使直接从官方示例中复制,也找不到未知类型名称QML_ELEMENT和 QML 模块
- 电源功能模块化操作
- 如何告诉本机节点模块所需的dll存储在哪里?
- 如何为模块化应用程序实现C++插件系统
- C++ Python 模块在 Blender 中崩溃,但在 Python 控制台中不会崩溃
- Arduino 模块化编程与全局和设置