Get the App
SLTechnology News&Howtos  ›  Development  › 

What libraries should be linked when Python is embedded in c

Shulou Source: shulou.com Published: 2022-06-02 23:25:44 10月03日 Update

Python embedded in c should be linked to the library what, I believe that many inexperienced people are helpless, for this reason this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.

//------------------------------------------ //cppobj.h // #include 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' After reading the above, do you know what libraries Python should link to when embedded in c? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Links mid-time content methods more problems helpless for this code reasons skills articles experience industry information information channels parts channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi Docker Linux vpn