SWIG教程问题
SWIG tutorial problems
我正在尝试遵循swig教程,但我卡住了,现在我正在使用:
- Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
- Vs2015 x64, Microsoft (R) C/c++优化编译器版本19.00.23918 for x64
- SWIG版本3.0.10
内容如下:
example.c
#include <time.h>
double My_variable = 3.0;
int fact(int n) {
if (n <= 1) return 1;
else return n*fact(n-1);
}
int my_mod(int x, int y) {
return (x%y);
}
char *get_time()
{
time_t ltime;
time(<ime);
return ctime(<ime);
}
的例子
%module example
%{
/* Put header files here or function declarations like below */
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
%}
extern double My_variable;
extern int fact(int n);
extern int my_mod(int x, int y);
extern char *get_time();
然后我做:
-
swig -python example.i
-
cl /D_USRDLL /D_WINDLL example.c example_wrap.c -Ic:Python351include /link /DLL /out:example.pyd /libpath:c:python351libs python35.lib
但是当我尝试python -c "import example"
时,我得到:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_example)
问题,发生了什么,我怎么解决它?
SWIG的动态链接模块的名称应该以下划线开头,在本例中为_example.pyd
。SWIG生成的Python文件正在查找名为_example
的模块,请参见该文件的开头:
from sys import version_info
if version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try: # ↓ SEE HERE
fp, pathname, description = imp.find_module('_example', [dirname(__file__)])
except ImportError:
import _example # ← AND HERE
return _example # ← AND HERE
if fp is not None:
try: # ↓ AND HERE
_mod = imp.load_module('_example', fp, pathname, description)
finally:
fp.close()
return _mod
_example = swig_import_helper() # ← AND HERE
del swig_import_helper
else: # ↓ AND HERE
import _example
它实际上是由SWIG包装的c++模块的名称。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- LLVM 万花筒教程 JIT 编译问题
- Arcsynthesis OpenGL 3.3 教程的问题 - MAKE 错误
- 编译 boost 文件系统的教程文件时遇到问题
- c++ /OpenGL教程(导入图像)后的问题
- SWIG教程问题
- CppCMS教程:静态链接模板错误(控制器问题)
- 理解指针的问题教程
- c++教程参考参数问题
- Boost Asio:关于教程的一些问题(同步日间服务器/客户端)
- Rastertek教程-问题与directx11 tut的第三部分