python 怎么调用c/c++ 写好的so ..
复制部分 代码(python ):
from ctypes import *
import os, sys, platform
if(platform.system() == "Linux"):
#dllFilename= os.path.join(os.path.dirname(__file__), "./Test.so")
ctypeLib = CDLL("./Test.so")
else:
pass
def Learnpython(str,number):
#ctypeLib.readString.argtypes = (c_char_p,c_int)
#p_type_1 = str.encode('ascii')
#p_type_2 = number.encode('ascii')
return ctypeLib.readString(str,number)
Learnpython('55',2)
这边是 c/c++ code ... (Test.cpp)
#include <stdio.h>
extern "C"
{
void readString(char*, int);
}
void readString(char* str, int length)
{
for (int i = 0; i < length; i++)
{
printf("%s \n", str);
}
}
g++ Test.cpp -fPIC -shared -o Test.so (生成so 库)