gpt4 book ai didi

python - SWIG - python 中的 C++ 代码

转载 作者:行者123 更新时间:2023-11-28 04:39:41 25 4
gpt4 key购买 nike

我尝试导入 SWING 生成的模块,但出现导入错误:

>>> 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
>>>

我按照 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

然后我尝试将我的函数外部到 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();
}

最佳答案

问题出在 c++ 命令上。您的 _ava.so 包含 SWIG 包装器,但缺少 turn_ai 等的实现。

仔细看SWIG Tutorial,有example.cexample.o,其中包含factmy_mod的实现

关于python - SWIG - python 中的 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50509539/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com