1. 准备开发环境
确保你的Ubuntu系统已经安装了必要的工具和依赖项。打开终端并运行以下命令:
sudo apt update
sudo apt install build-essential cmake git
2. 获取MQTT库
git clone https://github.com/eclipse/paho.mqtt.c.git
cd paho.mqtt.c
3. 编译MQTT库
mkdir build
cd build
cmake ..
make
sudo make install
4. 配置交叉编译
cd paho.mqtt.c
mkdir build-cross
cd build-cross
cmake -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc ..
make
5.传输和部署
编译完成后,将生成的库文件和相关的头文件传输到开发板
scp -r book@192.168.5.12:/home/book/linux/tool/mqtt/paho.mqtt.c/build-cross/src/libpaho-mqtt3c.so /home/root/tool/mqtt
scp -r book@192.168.5.12:/home/book/linux/tool/mqtt/paho.mqtt.c/build-cross/src/libpaho-mqtt3a.so /home/root/tool/mqtt
scp -r book@192.168.5.12:/home/book/linux/tool/mqtt/paho.mqtt.c/build-cross/src /home/root/tool/mqtt
scp -r book@192.168.5.12:/home/book/linux/tool/mqtt/paho.mqtt.c/src /home/root/tool/mqtt/include
注意
其库文件位置:
ubuntu:
/home/book/linux/tool/mqtt/paho.mqtt.c/build-cross/src
开发板:
/home/root/tool/mqtt/src
其头文件位置:
ubuntu:
/home/book/linux/tool/mqtt/paho.mqtt.c/src
开发板:
/home/root/tool/mqtt/include/src