作者:嘉苹民智79 | 来源:互联网 | 2023-01-01 13:24
我正在尝试使用SWIG为python包装这个简单的C++代码:
#include "hello.h"
int helloW()
{
std::cout <<"Hello, World!" ;
return 0;
}
这里是相对标题:
#include
int helloW() ; // decl
正如我正在使用的SWIG输入文件:
/* file : pyhello.i */
/* name of module to use*/
%module pyhello
%{
#include "hello.h"
%}
%include "hello.h";
现在,我的makefile(运行正常)是:
all:
swig -c++ -python -Wall pyhello.i
gcc -c -fpic pyhello_wrap.cxx hello.cpp -I/usr/include/python2.7
gcc -shared hello.o pyhello_wrap.o -o _pyhello.so
因为我能够从不同的来源汇总相关的问题在线.现在,一旦我尝试使用命令导入python我的库
>>> import pyhello
这是我得到的错误:
Traceback (most recent call last):
File "", line 1, in
File "pyhello.py", line 17, in
_pyhello = swig_import_helper()
File "pyhello.py", line 16, in swig_import_helper
return importlib.import_module('_pyhello')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: ./_pyhello.so: undefined symbol: _ZSt4cout
这让我觉得这个问题与命令有关,std::cout
或者一般来说与标准库有关
.
希望有人可以给我一些关于这个问题的提示.非常感谢提前!!
注意:同样的问题我尝试使用命令printf()
而不是std::cout
和库
而不是