- sudo tar jxvf ./openwrt-toolchain-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64 -C /opt/
- /openwrt-toolchain-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64替换为自己的文件路径
export PATH=/opt/openwrt-toolchain-ramips-mt76x8_gcc-7.3.0_musl.Linux-x86_64/toolchain-mipsel_24kc_gcc-7.3.0_musl/bin:$PATH
source /etc/bash.bashrc
mipsel-openwrt-linux-gcc -v
- cmake . -DPAHO_BUILD_STATIC=TRUE -DCMAKE_C_COMPILER=mipsel-openwrt-linux-gcc -DPAHO_WITH_SSL=FALSE
- mipsel-openwrt-linux-gcc是将静态库交叉编译成openwrt下可以运行的库
- 如果编译在linux下可以运行的就换成gcc
- -- The CXX compiler identification is unknown
- CMake Error at test/CMakeLists.txt:1 (PROJECT):
- No CMAKE_CXX_COMPILER could be found.
- Tell CMake where to find the compiler by setting either the environment
- variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
- to the compiler, or to the compiler name if it is in the PATH.
- -- Configuring incomplete, errors occurred!
原因是没有安装gcc和g++编译环境。安装方法很简单,一行命令搞定。在终端输入sudo apt-get install build-essential进行安装即可。为了查看是否安装上了,可以依次输入gcc --version、g++ --version来查看安装的gcc和g++的版本号。如果输出如下信息,则表明安装成功:
- gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
- Copyright (C) 2017 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
- Copyright (C) 2017 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
安装成功后,需要重启刚终端,然后再次输入cmake ..即可生成make文件
3)执行make命令
4)然后就可以在src目录下找到你的静态库了
5)静态库编译,使用Cmake
先修改CMakeLists.txt。
- $:cd paho.mqtt.c-master/
- $:mkdir target_lib
- $:cd target_lib/
- $:cmake ..
- $:sudo make
编译生成的库路径:
安装库到ubuntu
静态库安装:
- $:cp ~/work/mqtt/paho.mqtt.c-master/src/samples/MQTTAsync_*.c ./
- $: gcc MQTTAsync_subscribe.c -o MQTTAsync_subscribe -L/usr/local/lib -lpaho-mqtt3a-static -lpthread
- $: gcc MQTTAsync_publish.c -o MQTTAsync_publish -L/usr/local/lib -lpaho-mqtt3a-static -lpthread
联系客服