python调用C/C++程序出现的32位和64位的问题
最近在学习使用python调用C++程序。具体步骤是先用gcc生成.so文件,然后在python中调用。
具体大家可以参考博客:https://blog.csdn.net/taiyang1987912/article/details/44779719
看起来是比较方便的,但是却遇上了32位和64位问题的坑。所以记录下来,方便大家解决问题。
先给出C/C++代码和python代码:
#include <stdio.h>
#include <stdlib.h>
int func(int a, int b)
{
int ans = a + b;
printf("You input %d and %d\n", a, b);
printf("The result is %d\n", ans);
return ans;
}
python代码:
import ctypes
import platform
ll = ctypes.cdll.LoadLibrary
lib