下载mosqiitto源码,以mosquitto-1.5.9为例
mosquitto官方地址下载mosquitto-1.5.9.tar.gz
解压tar -zxvf mosquitto-1.5.9.tar.gz
下载NDK交叉编译链
下载链接android-ndk-r16b-linux-x86_64.zip
解压unzip android-ndk-r16b-linux-x86_64.zip
编译准备
如下mosquitto_android_cmake.sh编译脚本放入mosquitto-1.5.9目录
#!/bin/bash
CURRENT_DIR=$(dirname $(readlink -f $0))
rm -rf ./build
mkdir -p build
ANDROID_ABI="armeabi-v7a"
ANDROID_NDK="/home/kaober/disk4T1/raojun/android-ndk-r16b"
cmake \
-DANDROID_NDK=${ANDROID_NDK} \
-DANDROID_ABI=${ANDROID_ABI} \
-DANDROID_NDK_HOST_X64="YES" \
-DANDROID_NATIVE_API_LEVEL=22 \
-DANDROID_TOOLCHAIN_NAME="arm-linux-androideabi-4.9" \
-DCMAKE_TOOLCHAIN_FILE="/home/kaober/disk4T1/raojun/android-ndk-r16b/build/cmake/android.toolchain.cmake" \
-DWITH_TLS=OFF \
-DWITH_THREADING=OFF \
-H. -B./build
cd build
cmake --build .
cd ..
修改mosquitto-1.5.9目录下CMakeLists.txt
set (VERSION 1.5.9)
#add by kaober
add_compile_options(-fPIE)
add_compile_options(-fPIC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pie")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pie")
#add by kaober
......
运行脚本编译mosquitto_android_cmake.sh
build目录下生成如下目录
- client下面
mosquitto_pub 发布测试程序
mosquitto_sub 接受测试程序 - src下面
mosquitto 服务器程序
网友评论