Ubuntu16.04交叉编译openssl+mosquitto

在进行交叉编译过程时,Ubuntu16.04跟centOS是有明显的差距的,在Ubuntu上登录时默认采用普通用户登录,在操作的过程中需要记得添加 sudo,要不然就要出错了。再者就是在编译前的configure也是要添加sudo的,而且需要注意,在交叉编译前,务必给予交叉编译链执行权限,在配置过程中需要添加的交叉编译链的位置。
参看centos 下交叉编译的记录
比如:

./configure --host=arm-linux CC=arm-linux-gnueabihf-gcc --prefix=/opt/mosquitto/arm/ares

在实际执行时会报错
在这里插入图片描述
这里提示gcc没有工作,在这样配置之后就会 正常工作了。

sudo ./configure --host=arm-linux CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --prefix=/opt/mosquitto/arm/ares

以下为正式描述交叉编译的过程:

  • 1 openssl的交叉编译:(同时也是本次交叉编译的一项工作,而且为mosquitto交叉编译的基础,所以写在前面)
  • 版本 openssl1.1.1g
    下载:https://www.openssl.org/source/old/
    在交叉编译openssl1.1.1g时,通过Ubuntu16.04进行时总是不成功,所以我选择使用centos7进行,过程记录如下:
  • gcc编译:
sudo ./config --prefix=/opt/share/openssl-1.1.1g/build  -shared
# prefix配置makefile的install位置
sudo make
sudo make install
  • 交叉编译:
sudo ./config no-asm -shared --prefix=/opt/mosquitto/arm/ssl/ CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc CXX=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++
sudo make
sudo make install

(其中的–prefix后的内容为install要放的位置,CC和CXX填写的就是CC与C++程序所用编译链的路径)
在这里插入图片描述
注:如果遇到 “-m64” 错误,vim进入Makefile,找到"-m64"并删除;重新执行make
注:遇到这样的错误了,一共有两个-m64,查找方式:在vi编辑器下通过esc进入输入模式,/+要查找的内容就可以进行查找相关的内容
在这里插入图片描述
在这里插入图片描述
删除这两个-m64,然后就可以正常make了
在这里插入图片描述
编译过程中输出内容比较多,在此不再粘贴
在编译后,可以查看/opt/mosquitto/arm/ssl/lib下的so文件是否为ARM格式,通过file + *.so
如下通过:file libssl.so.1.1 可以看到是ARM类型的
在这里插入图片描述
在完成make install后,在include/openssl下的内容为要使用的头文件,在编译时对这些文件的位置有要求,在编译mosquitto时需要用到这些头文件。

  • 2 准备工作:cmake autoconf 和libtool的安装
    cmake-3.7.2
wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz

autoconf 用于生成configure文件

wget https://alpha.gnu.org/gnu/autoconf/autoconf-2.68b.tar.gz

libtool

wget https://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.gz

新建文件夹,便于以后将所有的移植操作放在这个文件夹内进行

 sudo mkdir /opt/mosquitto/
# 解压缩:tar -zxvf *.tar.gz
# 对于autoconf和libtool而言采用:
sudo ./configure
sudo make
sudo make install

对于cmake采用:

sudo ./bootstrap && make && make install

进行安装
然后执行cmake 出现:
在这里插入图片描述
就证明cmake已经安装完成了

  • 3 c-ares库交叉编译:
wget https://c-ares.haxx.se/download/c-ares-1.14.0.tar.gz
 
tar -zxvf c-ares-1.14.0.tar.gz
 
cd c-ares-1.14.0/
 
sudo ./configure --host=arm-linux CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --prefix=/opt/mosquitto/arm/ares

(注:测试时这里不指定CC,则编译出来 的内容不是ARM平台下的)
在这里插入图片描述
这个链不再是 ARM下的,在编译mosquitto时会出问题
在这里插入图片描述
如果以./configure --host=arm-linux CC=arm-linux-gnueabihf-gcc --prefix=/opt/mosquitto/arm/ares编译的则是正常的。

sudo make && make install

这里相关的截图不再展示,编译过程与openssl的编译相同
在编译出之后,可以查看到arm/areas/lib/内的so文件为ARM平台下的
在这里插入图片描述

sudo ./configure --host=arm-linux prefix=/opt/mosquitto/arm/e2fsprogs
 
sudo make
 
sudo make install

如果添加CC参数,则在编译中出现错误:
在这里插入图片描述
如果不添加CC参数,则出现平台为x86-64的程序:
在这里插入图片描述
但是按照这种方式编译之后,似乎并不会对后续的交叉编译有影响。

把lib下的uuid目录拷贝到安装目/home/mosquitto/arm/e2fsprogs下,

 sudo cp -r lib/uuid/ /opt/mosquitto/arm/e2fsprogs/

在arm/e2fsprogs下出现:
在这里插入图片描述

  • 5.mosquitto1.5.5交叉编译之cmake配置
    正题到了,前戏有点长,不过前戏一般是要好过正题的,前戏好了,正题就顺利的多了,如果前面的铺垫磕磕绊绊,挖坑无数,那到了正题也就秒了----执行make出现好多报错。
    前文铺垫了采用cmake的安装,在本文描述的是以cmake的 方式交叉编译的方式
    mosquitto 下载地址:https://mosquitto.org/files/source/
    在下载.tar.gz的文件之后进行解压,
tar -zxvf mosquitto-1.5.5.tar.gz
cd mosquitto-1.5.5/
vim CMakeList.txt

查找find_package 方式:输入模式下输入/find_package
找到CMakeList.txt中的find_package
添加:

set(OPENSSL_ROOT_DIR "/opt/mosquitto/arm/ssl")
set(OPENSSL_LIBRARIES "/opt/mosquitto/arm/ssl/lib/")

这里指出了openssl的位置
在这里插入图片描述
同样是这个文件找到:option(WITH_SRV “Include SRV lookup support?” ON)
这里的ON默认是OFF的,这里也需要修改,以配置UUID的位置
添加:

# Simple detect uuid
 
set(CMAKE_INCLUDE_PATH /opt/mosquitto/arm/e2fsprogs)
 
set(CMAKE_LIBRARY_PATH /opt/mosquitto/arm/e2fsprogs/uuid)
 
find_path(UUID_HEADER NAMES uuid/uuid.h)
 
if (UUID_HEADER)
 
    include_directories(${UUID_HEADER})
 
    message(STATUS "found uuid/uuid.h at:${UUID_HEADER}")
 
    find_library(UUID_LIBRARY NAMES uuid)
 
    if (UUID_LIBRARY)
 
        message(STATUS "found libuuid at:${UUID_LIBRARY}")
 
        set (LIBRARIES ${LIBRARIES} ${UUID_LIBRARY})
 
    else(UUID_LIBRARY)
 
        message(FATAL_ERROR "uuid library not found!" )
 
    endif (UUID_LIBRARY)
 
else (UUID_HEADER)
 
    message(WARNING "uuid library not found.")
 
endif (UUID_HEADER)

配置UUID的位置
在这里插入图片描述
然后:
修改目录中lib目录下的CMakeList.txt文件,注:上一个是mosquitto-1.5.5下,这里是mosquitto-1.5.5/lib下的

sudo vim lib/CMakeList.txt

找到:if (${WITH_SRV} STREQUAL ON)
在这里插入图片描述
这一段修改为:

if (${WITH_SRV} STREQUAL ON)
 
    # Simple detect c-ares
 
    find_path(ARES_HEADER ares.h /opt/mosquitto/arm/ares/include)
 
    if (ARES_HEADER)
 
        add_definitions("-DWITH_SRV")
 
        include_directories(${ARES_HEADER})
 
        message(STATUS "found ares.h at:${ARES_HEADER}")
 
        find_library(ARES_LIBRARY cares /opt/mosquitto/arm/ares/lib)
 
        if (ARES_LIBRARY)
 
            message(STATUS "found libcares at:${ARES_LIBRARY}")
 
            set (LIBRARIES ${LIBRARIES} ${ARES_LIBRARY})
 
        else(ARES_LIBRARY)
 
            message(FATAL_ERROR "not found libcares" )
 
        endif (ARES_LIBRARY)
 
    else (ARES_HEADER)
 
        message(WARNING "c-ares library not found.")
 
    endif (ARES_HEADER)
 
endif (${WITH_SRV} STREQUAL ON)

修改后的效果:
在这里插入图片描述
完成配置之后来到mosquitto-1.5.5目录下,通过CMakeList配置cmake:

sudo cmake -DCMAKE_C_COMPILER="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" -DCMAKE_CXX_COMPILER="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++" -DCMAKE_INSTALL_PREFIX=/opt/mosquitto/arm/mosquitto/  CMakeLists.txt

注:填写了编译链和install路径
在执行时会遇到:找不到openssl lib的情况
在这里插入图片描述
和找不到UUID LIB的情况
在这里插入图片描述
这是因为没有在CMakeCache.txt内配置openssl和UUID的路径。
配置openSSL
在CMakeCache.txt 内 搜索OPENSSL,找到这里进行修改

//Path to a library.
OPENSSL_CRYPTO_LIBRARY:FILEPATH=/opt/mosquitto/arm/ssl/lib/libcrypto.so

//Path to a file.
OPENSSL_INCLUDE_DIR:PATH=/opt/mosquitto/arm/ssl/include

//Path to a library.
OPENSSL_SSL_LIBRARY:FILEPATH=/opt/mosquitto/arm/ssl/lib/libssl.so
 tar -zxvf libuuid-1.0.3.tar.gz
 
cd libuuid-1.0.3/
 
sudo ./configure --host=arm-linux CC=/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --prefix=/opt/mosquitto/arm/libuuid
 
sudo make
 
sudo make install

在这里插入图片描述
在这里插入图片描述
将编译得到的libuuid的库文件复制到编译链的lib内:
在这里插入图片描述

cp /opt/mosquitto/arm/libuuid/lib/libuuid* 
/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/lib

在这里插入图片描述
通过cmake进行编译:

cmake -DCMAKE_C_COMPILER="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc" -DCMAKE_CXX_COMPILER="/opt/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++" -DCMAKE_INSTALL_PREFIX=/opt/mosquitto/arm/mosquitto/  CMakeLists.txt

在这里插入图片描述
这里我在原博客内没有找到,我查看了下CMakeCache.txt,在里面找到UUID_LIBRARY,
在这里插入图片描述
修改了库文件的位置后再次尝试:
在这里插入图片描述
至此终于完成了cmake的配置。

    1. mosquitto-1.5.5 的make和make install
      执行make
      在这里插入图片描述
      通过查找config.h可以发现内需要找到openssl/opensslconf.h,需要将这个文件夹放到mosquitto1.5.5文件夹内
sudo cp -r /opt/mosquitto/arm/ssl/include/openssl/ /opt/mosquitto/mosquitto-1.5.5/
sudo make  clean 
sudo make

再次make:
在这里插入图片描述
这里发现缺少了uuid/uuid.h,与上个问题相似,找到uuid的include文件夹

cp -r /opt/mosquitto/arm/libuuid/include/uuid/ /opt/mosquitto/mosquitto-1.5.5/
sudo make clean
sudo make

再次make
在这里插入图片描述
完成之后可以进行make install

过程中遇到的一些问题:
在这里插入图片描述

configure: error: no acceptable m4 could be found in $PATH

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值