阿里云OSS-C-SDK交叉编译环境配置记录

开发板环境是arm32架构的,开发环境是ubuntu18.04。

交叉编译环境配置

首先下载交叉编译工具:https://developer.arm.com/downloads/-/gnu-a
image.png
解压得到文件夹:gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf
新建文件夹 mkdir /opt/tool-chain
将编译链放在新建的文件夹下:
sudo mv gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf /opt/tool-chain/
将交叉编译环境添加到环境变量:
编辑.bashrc新增以下三行:

export ARCH=arm
export CROSS_COMPILE=arm-none-linux-gnueabihf-
export PATH=$PATH:/opt/tool-chain/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/bin

使其生效:source ~/.bashrc
通过查看交叉编译链的版本,确认是否成功配置:arm-none-linux-gnueabihf-gcc -v
image.png
有以上输出表示配置成功!
需要明确:交叉编译环境的路径为:/opt/tool-chain/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/

第三方库安装

sudo apt install cmake

curl 库安装

安装包:libcurl-7.32.0
下载地址:https://curl.se/download/curl-7.32.0.tar.gz
解压后得到:curl-7.32.0文件夹
安装过程:

cd curl-7.32.0
./configure --prefix=/home/cclike/curl --host=arm-none-linux CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-linux-gnueabihf-g++
make
make install

apr 库安装

安装包:apr-1.5.2
下载地址:https://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
解压后得到:apr-1.5.2文件夹
安装过程(安装之前可以先看看遇到的问题):

cd apr-1.5.2
./configure --prefix=/home/cclike/apr-1 --host=arm-none-linux CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-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:sudo apt install make
make install

遇到的问题:

  1. 执行./configuare的时候,会遇到下面的问题:
config.status: executing libtool commands
rm: cannot remove 'libtoolT': No such file or directory
config.status: executing default commands

解决方案:
编辑configuare文件,给RM添加啊参数:-f
image.png

  1. 执行make的时候遇到的问题:
cclike@RV1109:~/Downloads/apr-1.5.2$ make
make[1]: Entering directory '/home/cclike/Downloads/apr-1.5.2'
/home/cclike/Downloads/apr-1.5.2/build/mkdir.sh tools
/bin/bash /home/cclike/Downloads/apr-1.5.2/libtool --silent --mode=compile arm-none-linux-gnueabihf-gcc -g -O2   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I./include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include -I/home/cclike/Downloads/apr-1.5.2/include/private -I/home/cclike/Downloads/apr-1.5.2/include/private  -o tools/gen_test_char.lo -c tools/gen_test_char.c && touch tools/gen_test_char.lo
/bin/bash /home/cclike/Downloads/apr-1.5.2/libtool --silent --mode=link arm-none-linux-gnueabihf-gcc -g -O2   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I./include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include -I/home/cclike/Downloads/apr-1.5.2/include/private -I/home/cclike/Downloads/apr-1.5.2/include/private   -no-install    -o tools/gen_test_char tools/gen_test_char.lo    -lrt -lcrypt  -ldl
/home/cclike/Downloads/apr-1.5.2/build/mkdir.sh include/private
tools/gen_test_char > include/private/apr_escape_test_char.h
/bin/bash: tools/gen_test_char: cannot execute binary file: Exec format error
Makefile:141: recipe for target 'include/private/apr_escape_test_char.h' failed
make[1]: *** [include/private/apr_escape_test_char.h] Error 126
make[1]: Leaving directory '/home/cclike/Downloads/apr-1.5.2'
/home/cclike/Downloads/apr-1.5.2/build/apr_rules.mk:118: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

解决方案:

gcc -Wall -O2 -DCROSS_COMPILE tools/gen_test_char.c -s -o gen_test_char  // 确保已安装gcc sudo apt install gcc
./gen_test_char > ../include/private/apr_escape_test_char.h

修改当前目录的Makefile,禁止生成gen_test_char
image.png
保存退出之后重新执行make

遇到下面的问题:

cclike@RV1109:~/Downloads/apr-1.5.2$ make
make[1]: Entering directory '/home/cclike/Downloads/apr-1.5.2'
/bin/bash /home/cclike/Downloads/apr-1.5.2/libtool --silent --mode=compile arm-none-linux-gnueabihf-gcc -g -O2   -DHAVE_CONFIG_H  -DLINUX -D_REENTRANT -D_GNU_SOURCE   -I./include -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I./include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include/arch/unix -I/home/cclike/Downloads/apr-1.5.2/include -I/home/cclike/Downloads/apr-1.5.2/include/private -I/home/cclike/Downloads/apr-1.5.2/include/private  -o encoding/apr_escape.lo -c encoding/apr_escape.c && touch encoding/apr_escape.lo
In file included from ./include/apr_strings.h:52,
                 from encoding/apr_escape.c:31:
./include/apr_want.h:94:8: error: redefinition of 'struct iovec'
   94 | struct iovec
      |        ^~~~~
In file included from /opt/tool-chain/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/sys/socket.h:26,
                 from ./include/apr.h:168,
                 from ./include/apr_escape.h:22,
                 from encoding/apr_escape.c:28:
/opt/tool-chain/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/usr/include/bits/types/struct_iovec.h:26:8: note: originally defined here
   26 | struct iovec
      |        ^~~~~
/home/cclike/Downloads/apr-1.5.2/build/apr_rules.mk:206: recipe for target 'encoding/apr_escape.lo' failed
make[1]: *** [encoding/apr_escape.lo] Error 1
make[1]: Leaving directory '/home/cclike/Downloads/apr-1.5.2'
/home/cclike/Downloads/apr-1.5.2/build/apr_rules.mk:118: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

直接编辑对应文件,注释掉iovec结构体
image.png
重新直接make,编译通过

expat 库安装

安装这个库是因为在编译apr-util库的时候会报expat库的错

xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory#include <expat.h>

安装包:expat-2.2.5.tar.bz2
下载地址:https://github.com/libexpat/libexpat/releases/download/R_2_2_5/expat-2.2.5.tar.bz2
解压生成:expat-2.2.5
安装过程:

cd expat-2.2.5
./configure --prefix=/home/cclike/expat --host=arm-none-linux CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-linux-gnueabihf-g++
make
make install

apr-util 库安装

安装包:apr-util-1.5.4
下载地址:https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
解压生成:apr-util-1.5.4
安装过程:

cd apr-util-1.5.4
./configure --prefix=/home/cclike/apr-util --host=arm-none-linux CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-linux-gnueabihf-g++ --with-apr=/home/cclike/apr-1 --with-expat=/home/cclike/expat
make
make install

libmxml 库安装

安装包:mxml-2.8

下载地址:https://github.com/michaelrsweet/mxml/releases/download/release-2.8/mxml-2.8.tar.gz

解压生成:mxml-2.8

安装过程:

cd mxml-2.8
./configure --prefix=/home/cclike/mxml --host=arm-none-linux CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-linux-gnueabihf-g++
make
make install

遇到下面的问题:

cclike@RV1109:~/Downloads/mxml-2.8$ make
Compiling mxml-attr.c
Compiling mxml-entity.c
Compiling mxml-file.c
Compiling mxml-get.c
Compiling mxml-index.c
Compiling mxml-node.c
Compiling mxml-search.c
Compiling mxml-set.c
Compiling mxml-private.c
Compiling mxml-string.c
Creating libmxml.so.1.5...
Compiling mxmldoc.c
mxmldoc.c:913:1: warning: 'remove_directory' defined but not used [-Wunused-function]
 remove_directory(const char *path) /* I - Directory to remove */
 ^~~~~~~~~~~~~~~~
Linking mxmldoc...
Creating libmxml.a...
a - mxml-attr.o
a - mxml-entity.o
a - mxml-file.o
a - mxml-get.o
a - mxml-index.o
a - mxml-node.o
a - mxml-search.o
a - mxml-set.o
a - mxml-private.o
a - mxml-string.o
Compiling testmxml.c
Linking testmxml...
Testing library...
Makefile:352: recipe for target 'testmxml' failed
make: *** [testmxml] Error 2

目前还没有找到解决办法,但是上面的make动作已经生成了我们需要的头文件和链接库

image-20230426113144459

所以只需要将对应的文件拷贝出来即可:

image-20230426115958304

到这里第三方库基本上就安装完成了,说到底安装第三方库也只是为了得到对应的库文件和头文件。我的做法是把所有的库文件进行汇总,方便再makefile中进行引用。

image-20230426120802558

OSS-C-SDK 安装

安装包:aliyun-oss-c-sdk-3.5.0.tar.gz
下载地址:https://github.com/aliyun/aliyun-oss-c-sdk/archive/refs/tags/3.5.0.tar.gz
解压后得到:aliyun-oss-c-sdk-3.5.0
安装步骤:

cd aliyun-oss-c-sdk-3.5.0

编辑CMakeList.txt将下面内容添加到文件开头

SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/opt/tool-chain/arm-rockchip830-linux-uclibcgnueabihf/")
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 ${TOOLCHAIN_DIR}/bin/arm-rockchip830-linux-uclibcgnueabihf-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-rockchip830-linux-uclibcgnueabihf-g++)

修改apr和apr-util的路径为我们前面安装的路径:

FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /home/cclike/RV1109/oss/third_lib/apr-1/bin /usr/local/bin /usr/local/apr/bin/)
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /home/cclike/RV1109/oss/third_lib/apr-util/bin /usr/local/bin /usr/local/apr/bin/)

注释掉文件最后两行,这些是不需要的

# add_subdirectory(oss_c_sdk_sample)
# add_subdirectory(oss_c_sdk_test)

安装

cmake . \
	-DCMAKE_INSTALL_PREFIX=/home/cclike/RV1109/oss/sdk \
 	-DCURL_INCLUDE_DIR=/home/cclike/RV1109/oss/third_lib/curl/include \
  -DCURL_LIBRARY=/home/cclike/RV1109/oss/third_lib/curl/lib \
  -DAPR_INCLUDE_DIR=/home/cclike/RV1109/oss/third_lib/apr-1/include \
  -DAPR_LIBRARY=/home/cclike/RV1109/oss/third_lib/apr-1/lib \
  -DAPR_UTIL_INCLUDE_DIR=/home/cclike/RV1109/oss/third_lib/apr-util/include \
  -DAPR_UTIL_LIBRARY=/home/cclike/RV1109/oss/third_lib/apr-util/lib \
  -DMINIXML_INCLUDE_DIR=/home/cclike/RV1109/oss/third_lib/mxml/include \
  -DMINIXML_LIBRARY=/home/cclike/RV1109/oss/third_lib/mxml/lib \
  -DPTHREAD_LIBRARY=arm-rockchip830-linux-uclibcgnueabihf/sys-root/usr/lib/libpthread.a \
  -DMATH_LIBRARY=arm-rockchip830-linux-uclibcgnueabihf/sys-root/usr/lib/libm.a \
  -DRT_LIBRARY=arm-rockchip830-linux-uclibcgnueabihf/sys-root/usr/lib/librt.a
make
make install
posted @ 2023-07-13 14:32  可乐klelee  阅读(671)  评论(0编辑  收藏  举报