使用SWIG将使用blitz++数组的C++代码包装到python
嗨,你好啊,
我需要使用swg来包装我的C++类,该类大量使用blitz++数组来编写Python。以前有人这么做过吗?我在找一个简单的例子。
我在CFits.h中的导入:
选择 | 换行 | 行号
- #include <stdio.h>
- #include <iostream>
- #include <cstdlib>
- #include <blitz/array.h>
- #include <blitz/vector.h>
- #include <blitz/vector-et.h>
- #include <blitz/vecwhere.h>
- #include <blitz/tinyvec.h>
- #include <blitz/tinyvec-et.h>
- #include <fitsio.h>
- #include <fitsio2.h>
我的stelladrp.i文件:
选择 | 换行 | 行号
- %module stelladrp
- %{
- #include "cfits/src/CAny.h"
- #include "cfits/src/CFits.h"
- #include "mextract/src/MExtract.h"
- %}
- %include std_string.i
- using std::string;
- %include "cfits/src/CAny.h"
- %include "cfits/src/CFits.h"
- %include "mextract/src/MExtract.h"
我的命令:
选择 | 换行 | 行号
- swig -c++ -python -I/usr/local/include -I/usr/include stelladrp.i
- g++ -lm -fpic -std=c++11 -c mextract/src/MExtract.cpp stelladrp_wrap.cxx -I/usr/include/python2.7/
- g++ -shared MExtract.o stelladrp_wrap.o -o _stelladrp.so
导入stelladrp时的我的Python输出:
选择 | 换行 | 行号
- >>> import stelladrp
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "stelladrp.py", line 28, in <module>
- _stelladrp = swig_import_helper()
- File "stelladrp.py", line 24, in swig_import_helper
- _mod = imp.load_module('_stelladrp', fp, pathname, description)
- ImportError: ./_stelladrp.so: undefined symbol: _ZNK5CFits6SplIntERN5blitz5ArrayIdLi1EEES3_S3_dPd
- >>>