Ubuntu下交叉编译OSS
Ubuntu下交叉编译OSS
环境:Linux spider 4.15.0-88-generic #88~16.04.1-Ubuntu SMP Wed Feb 12 04:19:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
交叉编译工具: arm-linux-gnueabihf-g++
安装curl
# wget http://curl.haxx.se/download/curl-7.20.0.tar.gz
# tar xzvf curl-7.20.0.tar.gz
# cd curl-7.20.0
# ./configure --prefix=/root/curl --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++
# make
# make install
安装apr
# wget https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
# tar xzvf apr-1.7.0.tar.gz
# cd apr-1.7.0/
# ./configure --prefix=/root/apr-1/ --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes apr_cv_process_shared_works=yes apr_cv_mutex_robust_shared=yes apr_cv_tcp_nodelay_with_cork=yes ap_void_ptr_lt_long=no
# make
# make install
安装expat库
安装expat库是为下一步编译库做准备
下载url:https://sourceforge.net/projects/expat/files/expat/
# tar vxf expat-2.2.5.tar
# cd expat-2.2.5
# ./configure --prefix=/root/expat --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++
# make
# make install
安装apr-util
# git clone https://github.com/Distrotech/apr-util.git
# cd apr-util/
# ./configure --prefix=/root/apr-util --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-apr=/root/apr-1 --with-expat=/root/expat
# make
# make install
这里的--with-expat=/root/expat指定的就是上一步骤安装的依赖库
安装libmxml库
# wget --quiet https://github.com/michaelrsweet/mxml/releases/download/release-2.9/mxml-2.9.tar.gz
# tar xzvf mxml-2.9.tar.gz
# cd mxml-2.9
# ./configure --prefix=/root/libmxml --host=arm-linux-gnueabihf CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++
# make
#make install
这里注意,在下一步安装的时候有可能报错mxml.h中XXX结构体没有定义,原因是这里mxml版本的问题,笔者在这里安装的时候就报错了,笔者的解决方法是把低版本的头文件替换进来就可以了。
交叉编译OSS
下载
git clone https://github.com/aliyun/aliyun-oss-c-sdk.git
修改CMakeLists.txt文件
在文件头部添加如下内容
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/usr/arm-linux-gnueabihf")
SET(CMAKE_SYSTEM_PROCESSOR MIPS)
SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
如图所示
更改apr-1、apr-util和curl配置的检索路径
如图所示:
注释掉CMakeLists.txt文件的最后两行,这两行是编译oss_c_sdk_sample和oss_c_sdk_test的,和我们使用sdk没有太大关系
如图所示:
# mkdir build
# cd build
#
cmake .. -DCMAKE_INSTALL_PREFIX=/root/oss_c_sdk -DCURL_INCLUDE_DIR=/root/curl/include/ -DCURL_LIBRARY=/root/curl/lib/libcurl.a -DAPR_INCLUDE_DIR=/root/apr-1/include/apr-1/ -DAPR_LIBRARY=/root/apr-1/lib/libapr-1.a -DAPR_UTIL_INCLUDE_DIR=/root/apr-util/include/apr-1 -DAPR_UTIL_LIBRARY=/root/apr-util/lib/libaprutil-1.a -DMINIXML_INCLUDE_DIR=/root/libmxml/include/ -DMINIXML_LIBRARY=/root/libmxml/lib/libmxml.a -DPTHREAD_LIBRARY=/usr/arm-linux-gnueabihf/lib/libpthread.a -DM_LIBRARY=/usr/arm-linux-gnueabihf/lib/libm.a -DRT_LIBRARY=/usr/arm-linux-gnueabihf/lib/librt.a
# make
# make install
设置好环境变量后基本没有什么问题