使用SWIG将使用blitz++数组的C++代码包装到python

嗨,你好啊,
我需要使用swg来包装我的C++类,该类大量使用blitz++数组来编写Python。以前有人这么做过吗?我在找一个简单的例子。
我在CFits.h中的导入:

选择 | 换行 | 行号
  1.   #include <stdio.h>
  2.   #include <iostream>
  3.   #include <cstdlib>
  4.   #include <blitz/array.h>
  5.   #include <blitz/vector.h>
  6.   #include <blitz/vector-et.h>
  7.   #include <blitz/vecwhere.h>
  8.   #include <blitz/tinyvec.h>
  9.   #include <blitz/tinyvec-et.h>
  10.   #include <fitsio.h>
  11.   #include <fitsio2.h>

我的stelladrp.i文件:

选择 | 换行 | 行号
  1. %module stelladrp
  2. %{
  3. #include "cfits/src/CAny.h"
  4. #include "cfits/src/CFits.h"
  5. #include "mextract/src/MExtract.h"
  6. %}
  7. %include std_string.i
  8. using std::string;
  9. %include "cfits/src/CAny.h"
  10. %include "cfits/src/CFits.h"
  11. %include "mextract/src/MExtract.h"

我的命令:

选择 | 换行 | 行号
  1. swig -c++ -python -I/usr/local/include -I/usr/include stelladrp.i
  2. g++ -lm -fpic -std=c++11 -c mextract/src/MExtract.cpp stelladrp_wrap.cxx -I/usr/include/python2.7/
  3. g++ -shared MExtract.o stelladrp_wrap.o -o _stelladrp.so

导入stelladrp时的我的Python输出:

选择 | 换行 | 行号
  1. >>> import stelladrp
  2. Traceback (most recent call last):
  3.   File "<stdin>", line 1, in <module>
  4.   File "stelladrp.py", line 28, in <module>
  5.     _stelladrp = swig_import_helper()
  6.   File "stelladrp.py", line 24, in swig_import_helper
  7.     _mod = imp.load_module('_stelladrp', fp, pathname, description)
  8. ImportError: ./_stelladrp.so: undefined symbol: _ZNK5CFits6SplIntERN5blitz5ArrayIdLi1EEES3_S3_dPd
  9. >>>

标签: python

添加新评论