Python嵌入c中時(shí)應(yīng)該鏈接的庫(kù)有哪些
如果你對(duì)把Python嵌入c中時(shí)應(yīng)該鏈接時(shí)有哪些庫(kù)可以對(duì)其進(jìn)行連接時(shí),你就可以點(diǎn)擊我們的文章進(jìn)行觀看,對(duì)把Python嵌入c中時(shí)應(yīng)該鏈接的庫(kù)有所了解,以下是文章的具體介紹,望你會(huì)有所啊后或。
- //------------------------------------------
- //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中時(shí)應(yīng)該鏈接庫(kù)的相關(guān)代碼的前部分介紹做完之后還要
- $ mv _cppobj.so _cppobj.pyd
然后就可以
- >>> from cppobj import cppobj
- >>> c = cppobj('Hello')
- >>> c.show()
- 'Hello'
很久以前記的筆記,希望能幫上忙Top以上就是對(duì)把Python嵌入c中時(shí)應(yīng)該鏈接庫(kù)的相關(guān)代碼的介紹,望你會(huì)有所收獲。
【編輯推薦】