Python嵌入c中时应该链接的库有哪些,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
//------------------------------------------ //cppobj.h // #include <iostream> using namespace std; class cppobj { private : string s; public : cppobj(string a): s(a) {}; string show() {return s;} }; //----------------------------------------- //------------------------------------------ //cppobj.i %module cppobj %include "std_string.i" %{ #include "cppobj.h" %} %include "cppobj.h" //------------------------------------------ //------------------------------------------ // Makefile _cppobj.so: cppobj_wrap.o g++ -o $@ $< -shared -fpic -lpython24 cppobj_wrap.cxx: cppobj.i cppobj.h swig -c++ -python cppobj.i cppobj_wrap.o: cppobj.h cppobj_wrap.cxx g++ -c cppobj_wrap.cxx -fpic -IC:/Python24/include clean: rm -rf cppobj_wrap.cxx _cppobj.so *.o cppobj.py cppobj.pyc //------------------------------------------
把Python嵌入c中时应该链接库的相关代码的前部分介绍做完之后还要
$ mv _cppobj.so _cppobj.pyd
然后就可以
>>> from cppobj import cppobj >>> c = cppobj('Hello') >>> c.show() 'Hello'
看完上述内容,你们掌握Python嵌入c中时应该链接的库有哪些的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网行业资讯频道,感谢各位的阅读!