0

I tried to import the SWING generated module, but I got an 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 -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:

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();
}
2
  • Now I modified my ava.i from /* ava.i */ %module ava %{ /* Put header files here or function declarations like below */ #include "koord.h" extern koord turn_ai(int** t, int player, int K, int J); %} %include "koord.h" extern koord turn_ai(int** t, int player, int K, int J); to /* ava.i */ %module ava %{ /* Put header files here or function declarations like below */ #include "koord.h" extern "C" koord turn_ai(int** t, int player, int K, int J); %} %include "koord.h" extern "C" koord turn_ai(int** t, int player, int K, int J); Commented May 24, 2018 at 12:39
  • But it's still the same error, just the end is now undefined symbol: turn_ai Commented May 24, 2018 at 12:42

1 Answer 1

1

The problem is with the c++ commands. Your _ava.so contains the SWIG wrappers, but is missing the implementations for turn_ai etc.

Look carefully at the SWIG Tutorial, there are example.c and example.o which contain implementations of fact, my_mod, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.