Ste*_*and 3 c++ python linux swig
遵循网络上的不同教程,我尝试使用SWIG在python中制作c ++类的包装。
我的课看起来像这样:
/*file libraryInstance.h*/
struct LibraryInstance
{
void init();
void terminate();
private:
std::shared_ptr<AnObject> m_spAnObject;
};
Run Code Online (Sandbox Code Playgroud)
对于python博览会,我做了这个.i文件:
%module LibraryInstance
%{
#include "libraryInstance.h"
%}
%include "libraryInstance.h"
Run Code Online (Sandbox Code Playgroud)
然后我已经执行了命令 swig -c++ -python -o ./src/libraryInstance_wrap.cpp ./src/libraryInstance.i
没有任何输出错误,swig生成了两个文件,libraryInstance_wrap.cpp并且LibraryInstance.py
然后,我编译c ++文件,包括libraryInstance_wrap.cpp。所有编译正常,我得到了我的库.so文件。
当我查看生成的swig时LibraryInstance.py,我可以清楚地看到class LibraryInstance:
但是,当我启动命令时python LibraryInstance.py,在与.so相同的目录中,我看到以下错误输出:
Traceback (most recent call last):
File "LibraryInstance.py", line 26, in <module>
_LibraryInstance = swig_import_helper()
File "LibraryInstance.py", line 18, in swig_import_helper
import _LibraryInstance
ImportError: No module named _LibraryInstance
Run Code Online (Sandbox Code Playgroud)
当我查看LibraryInstance.py的代码时,看起来好像抛出了异常ImportError,Python无法找到该模块。(第18行)。
知道该怎么做才能更正吗?