Python嵌入c中时应该链接的库有哪些


如果你对把Python嵌入c中时应该链接时有哪些库可以对其进行连接时,你就可以点击我们的文章进行观看,对把Python嵌入c中时应该链接的库有所了解,以下是文章的具体介绍,望你会有所啊后或。

  1. //------------------------------------------   
  2. //cppobj.h   
  3. //   
  4. #include <iostream>   
  5. using namespace std;   
  6. class cppobj {   
  7. private :   
  8. string s;   
  9. public :   
  10. cppobj(string a): s(a) {};   
  11. string show() {return s;}   
  12. };   
  13. //-----------------------------------------   
  14. //------------------------------------------   
  15. //cppobj.i   
  16. %module cppobj   
  17. %include "std_string.i"   
  18. %{   
  19. #include "cppobj.h"   
  20. %}   
  21. %include "cppobj.h"   
  22. //------------------------------------------   
  23. //------------------------------------------   
  24. // Makefile   
  25. _cppobj.so: cppobj_wrap.o   
  26. g++ -o $@ $< -shared -fpic -lpython24   
  27. cppobj_wrap.cxx: cppobj.i cppobj.h   
  28. swig -c++ -python cppobj.i   
  29. cppobj_wrap.o: cppobj.h cppobj_wrap.cxx   
  30. g++ -c cppobj_wrap.cxx -fpic -IC:/Python24/include   
  31. clean:   
  32. rm -rf cppobj_wrap.cxx _cppobj.so *.o cppobj.py cppobj.pyc   
  33. //------------------------------------------   

把Python嵌入c中时应该链接库的相关代码的前部分介绍做完之后还要

  1. $ mv _cppobj.so _cppobj.pyd  

然后就可以

  1. >>> from cppobj import cppobj   
  2. >>> c = cppobj('Hello')   
  3. >>> c.show()   
  4. 'Hello'  

很久以前记的笔记,希望能帮上忙Top以上就是对把Python嵌入c中时应该链接库的相关代码的介绍,望你会有所收获。

相关内容

    暂无相关文章

评论关闭