##int foo (int a, int b) { printf ("youinput%d and%d\n c8> ", A, b); return A +
Gcc-o Libpycall.so-shared-fpic PYCALL.C
Import ctypesll=ctypes.cdll.LoadLibrarylib=ll ('/users/***/libpycall.so' )print lib.foo (1,3)
Python calls C + + (Class) dynamic-link library
extern "C" is required to assist, that is, you can only call the C function, you cannot call the method directly, but you can parse the C + + method. Instead of using extern "C", the built-in dynamic-link library does not have a symbol table for these functions.
#include <iostream>using namespace std;classtestlib{public:void display (); void display (int a);}; void TestLib::d isplay () {cout<<"First display"<<Endl;} void TestLib::d isplay (int a) {cout<<"Second Display:"<<a<<Endl;} extern"C"{TestLib obj; void display () {obj.display (); } void Display_int () {Obj.display (2); }}
g++-O libpycallclass.so-shared-fpic pycallclass.cpp
Import== SO ("/user/***/libpycallclass.so")Print 'display ()'lib.display ()print'display ( (+)'lib.display_int (100)
Python calls C + +