pynq-z2引入.so文件遇到的问题

在pynq-z2想在其中引入C语言进行调用,首先要生成.so文件

一系列问题如下

OSError: : decode.so:unexpected reloc type 0x03

用新的编译工具使用-fPIC(-fpic -pie)选项重新编译相关依赖库文件,依赖库目标文件避免出现TEXTREL标识。

gcc decode.cpp -shared -fPIC  -o decode.so

又出错

AttributeError: ./decode.so: undefined symbol: YOLOdecode
ldd -r decode.so

查看缺少什么东西

我把exp函数的math.h删了,自己写了近似的函数

double exp(float x)
{
    x = 1.0 + x / 256.0;
    x *= x; x *= x; x *= x; x *= x;
    x *= x; x *= x; x *= x; x *= x;
    return x;
}
nm -D decode.so

查看含有什么函数

知道函数名字是_Z10YOLOdecodePA13_A13_fPA6_fRi。

import ctypes

lib = ctypes.cdll.LoadLibrary("./decode.so") 

但是又有问题

ArgumentError: argument 1: <class 'TypeError'>: Don't know how to convert parameter 1

改一下输入数据格式

lib._Z10YOLOdecodePA13_A13_fPA6_fRi.argtypes = [ctypes.c_float, ctypes.c_float,ctypes.c_int]

还是有问题

ArgumentError: argument 1: <class 'TypeError'>: wrong type

改为数组空间

在ctypes中,基于前述的基本数据类型,还可以构建自定义的数组类型,自定义数组类型的方法: 新类型名 = ctypes基本类型名*长度n,赋值方法:对象名=新类型名(赋值1,赋值2……赋值n) ; 

lib._Z10YOLOdecodePA13_A13_fPA6_fRi.argtypes = [ctypes.c_float*125*13*13, ctypes.c_float*845*6,ctypes.c_int]
ArgumentError: argument 1: <class 'TypeError'>: expected c_float_Array_125_Array_13_Array_13 instance instead of PynqBuffer

哎,没解决

  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值