当前位置: 代码迷 >> 综合 >> 安卓移植paho.mqtt.c的那些坑
  详细解决方案

安卓移植paho.mqtt.c的那些坑

热度:0   发布时间:2024-03-05 21:12:40.0

编译:

mkdir build_android
cd build_android
cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/out_android -DPAHO_BUILD_STATIC=TRUE -DCMAKE_C_COMPILER=arm-linux-androideabi-gcc
make -j16

报错:

1、ld: error: cannot find -lpthread

解决方法:将所有-lpthread替换为-pthread,最好直接将整个工程添加到vscode或其他工具中全部替换,因为要替换的地方很多

2、ld: error: cannot find -lrt

解决方法:安卓4.8的工具链中居然没有librt这个库,从安卓SDK中找到这个库粘贴到交叉编译工具链对应目录即可;

3、WebSocket.c:function WebSocket_receiveFrame: error: undefined reference to 'be64toh'

解决方法:除了这个be64toh找不到,be16toh、be32toh,全部都找不到,去找到交叉编译工具链里面的endian.h中发现,安卓的交叉编译工具链中这个几个宏分别被定义成:betoh16、betoh32、betoh64,将源码中用到be16toh、be32toh、be64toh的地方替换成之前的即可;