简体   繁体   English

SWIG-Python中的C ++代码

[英]SWIG - C++ code in python

I tried to import the SWING generated module, but I got an ImportError: 我尝试导入SWING生成的模块,但是出现了ImportError:

>>> import ava
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ava.py", line 28, in <module>
    _ava = swig_import_helper()
  File "ava.py", line 24, in swig_import_helper
    _mod = imp.load_module('_ava', fp, pathname, description)
ImportError: ./_ava.so: undefined symbol: _Z7turn_aiPPiiii
>>> 

I followed SWIG's tutorial ( http://www.swig.org/tutorial.html ) and I compiled my main.cpp like this: 我遵循了SWIG的教程( http://www.swig.org/tutorial.html ),并这样编译了main.cpp:

swig -python -c++ ava.i
c++ -fPIC -c ava_wrap.cxx -I/usr/include/python2.7/
c++ -shared ava_wrap.o -o _ava.so

and I tried to extern my functions to c: 我试图将我的功能扩展到c:

extern "C" {
  bool isEnd(int** t, int x, int y, int K, int J);
  void tout(int** t, int K);
  koord turn(int** t, int player, int K, int J);
  koord turn_ai(int** t, int player, int K, int J);
  bool isPat(int** t, int K);
  ai_res turn_ai_3x3_v2(int** t, int turn);
  ai_res turn_ai_pre(int** t, int turn, int K, int J, int dep);
  ai_res turn_ai_(int** t, int turn, int K, int J, int ab, int dep);
  bool isSeparated(int** t, int K, int i, int j);
  std::vector<koord> stepsFun(int** t, int K);
  bool isEmpty(int** t, int K);
  int value(int** t, int K);
  int fofug();
}

The problem is with the c++ commands. 问题出在c++命令。 Your _ava.so contains the SWIG wrappers, but is missing the implementations for turn_ai etc. 您的_ava.so包含SWIG包装器,但缺少turn_ai等的实现。

Look carefully at the SWIG Tutorial, there are example.c and example.o which contain implementations of fact , my_mod , etc. 仔细查看SWIG教程,其中有example.cexample.o ,其中包含factmy_mod等的实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM