If you have any libraries to connect to when embedding Python in c, you can click our article to view it, I have some knowledge about the libraries that should be linked when I embed Python into c. The following is a detailed introduction of the article. I hope you will have some experience later or later.
- //------------------------------------------
- //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
- //------------------------------------------
When we embed Python into c, we need to link the first part of the relevant code of the library.
- $ mv _cppobj.so _cppobj.pyd
Then you can
- >>> from cppobj import cppobj
- >>> c = cppobj('Hello')
- >>> c.show()
- 'Hello'
I hope you can take notes from a long time ago. Top-up is an introduction to the Code related to the link library when you embed Python into c. I hope you will gain some benefits.