前些时间遇到七牛云第三方编译问题,现把整个流程记录如下,供大家参考.
我们使用的开发板是周立功的m1808,核心是rk1808.环境在Vmware的linux下面
一.编译依赖库curl
百度云下载链接:
链接:https://pan.baidu.com/s/1J-hKk4Pce9gf5rBcqcOtYw 提取码:pkgb
1.下载源文件到本地
2.解压文件到当前目录
tar xvf curl-7.58.0.tar.xz
3.进入目录curl-xxx,创建build文件夹
mkdir build cd build
4.加载第三方编译链的目录环境变量
export PATH=$PATH:/opt/zlg/m1808-sdk-v1.3.1-ga/host/bin //加载aarch64-linux-gnu目录
我们的编译链接版本是
#aarch64-linux-gnu-gcc -v 使用内建 specs。 COLLECT_GCC=/opt/zlg/m1808-sdk-v1.3.1-ga_2020.12.31/host/../gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/opt/zlg/m1808-sdk-v1.3.1-ga_2020.12.31/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../libexec/gcc/aarch64-linux-gnu/6.3.1/lto-wrapper 目标:aarch64-linux-gnu 配置为:'/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/snapshots/gcc.git~linaro-6.3-2017.05/configure' SHELL=/bin/bash --with-mpc=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-mpfr=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gmp=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu --with-gnu-as --with-gnu-ld --disable-libmudflap --enable-lto --enable-shared --without-included-gettext --enable-nls --disable-sjlj-exceptions --enable-gnu-unique-object --enable-linker-build-id --disable-libstdcxx-pch --enable-c99 --enable-clocale=gnu --enable-libstdcxx-debug --enable-long-long --with-cloog=no --with-ppl=no --with-isl=no --disable-multilib --enable-fix-cortex-a53-835769 --enable-fix-cortex-a53-843419 --with-arch=armv8-a --enable-threads=posix --enable-multiarch --enable-libstdcxx-time=yes --enable-gnu-indirect-function --with-build-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/sysroots/aarch64-linux-gnu --with-sysroot=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu/aarch64-linux-gnu/libc --enable-checking=release --disable-bootstrap --enable-languages=c,c++,fortran,lto --build=x86_64-unknown-linux-gnu --host=x86_64-unknown-linux-gnu --target=aarch64-linux-gnu --prefix=/home/tcwg-buildslave/workspace/tcwg-make-release/builder_arch/amd64/label/tcwg-x86_64-build/target/aarch64-linux-gnu/_build/builds/destdir/x86_64-unknown-linux-gnu 线程模型:posix gcc 版本 6.3.1 20170404 (Linaro GCC 6.3-2017.05)
5.检测配置并编译源码
参数解释: 【–host】:就是用【config.guess】获取的; 【CC】【CXX】:交叉编译工具链gcc和g++名称; 【–with-protoc】:已经编译好的主机平台protoc二进制文件路径; 【–prefix】:交叉编译后安装目录。
../configure --host=aarch64-linux-gnu --prefix=/usr make make install DESTDIR=/home/zlgmcu/Desktop/curl-7.58.0/build/output //此处为实际的目录
6.安装到指定目录
make install DESTDIR=/home/zlgmcu/Desktop/curl-7.58.0/build/output
至此,libcurl 编译完成
7.完整命令如下(重要)
tar -xvf curl-7.58.0.tar.xz cd curl-7.58.0 mkdir build export PATH=$PATH:/opt/zlg/m1808-sdk-v1.3.1-ga/host/bin //加载aarch64-linux-gnu目录
../configure --host=aarch64-linux-gnu --prefix=/usr
make
make install DESTDIR=/home/zlgmcu/Desktop/curl-7.58.0/build/output //此处为实际的目录
二、交叉编译七牛云库
1.下载代码到本地
git clone https://github.com/qiniu/c-sdkv
如果网速不好也可以用我们提供的国内镜像
git clone https://gitee.com/cqnews/c-sdk
2.编写Makefile文件
INCLUDE_PATH=-Ibase64 -IcJSON -Iqiniu SOURCE_FILES= b64/b64.c b64/urlsafe_b64.c cJSON/cJSON.c qiniu/auth_mac.c qiniu/base.c qiniu/base_io.c qiniu/cdn.c qiniu/conf.c qiniu/fop.c qiniu/http.c qiniu/io.c qiniu/macro.h qiniu/qetag.c qiniu/reader.c qiniu/resumable_io.c qiniu/rs.c qiniu/tm.c all: $(SOURCE_FILES)
aarch64-linux-gnu-gcc -g -c -fPIC $^ $(INCLUDE_PATH) -lcurl -lcrypto -lssl -lm
3.编译目标文件
make
上面的Makefile是把所有代码编译为.o
目标文件
4.使用工具ar
打包为静态库
ar rcs libqiniu.a *.o
5.基于.o
文件构建动态库
aarch64-linux-gnu-gcc -shared -o libqiniu.so *.o -lcurl -lcrypto -lssl -lm
6.最终得到的构建完毕的发布包
. ├── include │ ├── b64 │ │ ├── b64.h │ │ └── urlsafe_b64.h │ ├── cJSON │ │ └── cJSON.h │ └── qiniu │ ├── base.h │ ├── cdn.h │ ├── conf.h │ ├── fop.h │ ├── http.h │ ├── io.h │ ├── macro.h │ ├── qetag.h │ ├── reader.h │ ├── region.h │ ├── resumable_io.h │ ├── rs.h │ └── tm.h └── lib ├── libqiniu.a └── libqiniu.so