Ubuntu 交叉编译openssl + pahomqtt

(一)交叉编译openssl

1 下载openssl

下载链接:/source/index.html

2 解压openssl

tar -xzvf openssl-3.0.9.tar.gz

3 配置其config编译条件

~/Downloads/openssl-3.0.9$ 
./config no-asm -shared --prefix=/home/cidi/Downloads/openssl_arm no-async

4 修改OpensslMakefile文件,配置其make的编译器

vim Makefile

(1)修改:

CC=$(CROSS_COMPILE)gcc
CXX=$(CROSS_COMPILE)g++

为:

CC=$(CROSS_COMPILE)aarch64-linux-gnu-gcc
CXX=$(CROSS_COMPILE)aarch64-linux-gnu-g++

(2)搜索-m64选项并删除,共两处(否则make后会报错)

/-m64

5 make

make
make install

(二) 交叉编译paho-mqtt

1 编译paho.mqtt.c

创建build_arm文件夹,进入build_arm后运行:

cmake .. -DCMAKE_INSTALL_PREFIX=/home/cidi/Downloads/pahomqtt_install_arm  -DPAHO_BUILD_STATIC=TRUE -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc

make
sudo make install

2 编译paho.mqtt.cpp

修改CMakeLists.txt,加入下面四行

set (CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc")
set (CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")  
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")

创建build_arm文件夹,进入build_arm后运行:

export CC=/usr/bin/aarch64-linux-gnu-gcc
cmake .. -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_INSTALL_PREFIX=/home/cidi/Downloads/pahomqtt_install_arm -DPAHO_MQTT_C_LIBRARIES=/home/cidi/Downloads/pahomqtt_install_arm/lib/libpaho-mqtt3a.so -DPAHO_MQTT_C_INCLUDE_DIRS=/home/cidi/Downloads/pahomqtt_install_arm/include -DOPENSSL_SSL_LIBRARY=/home/cidi/Downloads/openssl_arm/lib64/libssl.so -DOPENSSL_INCLUDE_DIR=/home/cidi/Downloads/openssl_arm/include -DOPENSSL_CRYPTO_LIBRARY=/home/cidi/Downloads/openssl_arm/lib64/libcrypto.so 

make
sudo make install


参考文章:

ubuntu编译paho_mqtt_cpp_paho编译_Thera777的博客-CSDN博客

你可能感兴趣的:(ubuntu,服务器,linux)