概述
#include "hello.h"
int helloW()
{
std::cout << "Hello,World!" ;
return 0;
}
这里是相对标题:
#include
正如我正在使用的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 "
__init__.py",line 37,in import_module
__import__(name)
ImportError: ./_pyhello
.so: undefined symbol: _ZSt4cout
这让我觉得这个问题与命令std :: cout相关,或者一般来说,与标准库< iostream>相关.
希望有人可以给我一些关于这个问题的提示.非常感谢提前!!
注意:同样的问题我尝试使用命令printf()而不是std :: cout和库< cstdio>而不是< iostream>
ImportError: ./_pyhello.so: undefined symbol: _ZSt4cout
用c filt _ZSt4cout你会发现它是std :: cout(name mangling).
你应该使用g,而不是gcc,尤其是你的链接器命令(带-shared).
或者您需要显式链接某些-lstdc您的共享库.
阅读Drepper的How to Write Shared Libraries(因为Python是dlopen(3),然后是dlsym(3)).
你最好声明为extern“C”int helloW(void);你的日常工作(阅读C++ dlopen minihowto).
总结
以上是编程之家为你收集整理的使用SWIG包装python的C代码.无法使用cout命令全部内容,希望文章能够帮你解决使用SWIG包装python的C代码.无法使用cout命令所遇到的程序开发问题。
如果您也喜欢它,动动您的小指点个赞吧