阿里云官方地址:
https://github.com/aliyun/aliyun-oss-c-sdk/blob/master/README-CN.md
目前device平台设备为嵌入式linux环境,故选择使用C-SDK作为开发接口包实现对OSS基本操作是应用。
依赖库:
源码:https://curl.haxx.se/download.html
./configure --prefix=/home/jw.li/work/v50/osssdk/curl --host=arm-openwrt-linux CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-g++
Make
Make install
- –prefix: 安装目录 即make install之后 include lib 位置所在目录。(后面相同就不说了)
- –host:该软件将要运行的平台
- CC:交叉编译gcc工具
- CXX:交叉编译g++工具
curl 很给面子 很容易就成功了
跟着阿里小哥走 用的1.5.2
完整编译流程见3.3
./configure CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-g++ --host=arm-openwrt-linux --prefix=/home/jw.li/work/v50/osssdk/apr 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
解决:
vi include/apr_want.h
在编译的过程中会提示“iovec定义重复”在/apr/include目录。修改apr_want.h文件。将
#ifndef APR_IOVEC_DEFINED
#define APR_IOVEC_DEFINED
struct iovec
{
void *iov_base;
size_t iov_len;
};
#endif /* !APR_IOVEC_DEFINED */
改为
#if 0
struct iovec
{
void *iov_base;
size_t iov_len;
};
#endif /* !APR_IOVEC_DEFINED */
tools/gen_test_char > include/private/apr_escape_test_char.h
/bin/bash: tools/gen_test_char: cannot execute binary file: Exec format error
原因:
因为gen_test_char 使用编译工具编译出来的,但交叉编译出的gen_test_char这个工具在宿主机上无法使用,
所以可以先./configure 再make 将工具保存起来 在执行交叉编译configure,再把工具cp回原位置并修改makefile 执行即解决
1 ./configure
2 Make
3 cp -a tools/gen_test_char ..
4 Make clean
5 ./configure CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-ma-linux-g++ --host=arm-openwrt-linux --prefix=/home/jw.li/work/v50/osssdk/apr 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
6 cp -a ../gen_test_char tools/
7 Vim Makefile
134 行
OBJECTS_gen_test_char = tools/gen_test_char.lo $(LOCAL_LIBS)
屏蔽
#OBJECTS_gen_test_char = tools/gen_test_char.lo $(LOCAL_LIBS)
目的是不生成新的gen_test_char文件
8 vi include/apr_want.h 第93行 #ifndef APR_IOVEC_DEFINED 替换成#if 0
Make
Make install
./configure CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-g++ --host=arm-openwrt-linux --prefix=/home/jw.li/work/v50/osssdk/apr-util --with-apr=/home/jw.li/work/v50/osssdk/apr --with-expat=/home/jw.li/work/v50/osssdk/expat_code/libexpat/expat
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include
网上PC平台说 是说缺少了 xml 的解析器。查阅网络资料后找到了解决方案,yum 安装一个 expat-devel 包即可。
脸上笑嘻嘻, 来吧让我们开始吧:
–with-expat=DIR 即加上这个参数 所以需要我们交叉编译expat
git clone https://github.com/libexpat/libexpat.git
cd expat/
./buildconf.sh
./configure --prefix=/home/jw.li/work/v50/osssdk/expat --with-docbook -host=arm-openwrt-linux CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-g++
automake
make
报错:
ERROR: Configure with –with-docbook for “make dist”.
Makefile:567: recipe for target ‘xmlwf.1’ failed
make[1]: * [xmlwf.1] Error 1
不管 接着make install
发现安装目录下还是生成了想要的文件。
–with-expat=/home/jw.li/work/v50/osssdk/expat expat安装目录加入到apr-util-1.5.4 configure中。
修改:
apr-util-1.5.4/xlate/xlate.c的handle_special_names函数,直接关掉本地编码相关的两个判断,直接返回return page; 即:72 75行
// return apr_os_default_encoding(pool);
return page;
来源:http://blog.csdn.net/freeman1975/article/details/53482713
./configure CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-ma-linux-g++ --host=arm-openwrt-linux --prefix=/home/jw.li/work/v50/osssdk/apr-util --with-apr=/home/jw.li/work/v50/osssdk/apr --with-expat=/home/jw.li/work/v50/osssdk/expat_code/libexpat/expat --with-expat=/home/jw.li/work/v50/osssdk/expat
Make
Make install
这个库版本很奇怪,阿里小哥推荐2.80 但是 这个库2.80,2.90之后又变成了2.10 (更新时间上看)
所以用的就是2.10
./configure --prefix=/home/jw.li/work/v50/osssdk/mxml --host=arm-openwrt-linux CC=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-gcc CXX=/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi/bin/arm-openwrt-linux-g++
报错:
./testmxml: 1: ./testmxml: Syntax error: word unexpected (expecting “)”)
Makefile:352: recipe for target ‘testmxml’ failed
make: * [testmxml] Error 2
报错交叉编译出来肯定不能通过测试 所以我们直接把so和h文件复制走,并建立mxml下面把 include 和lib复制进去 供oss_c_sdk使用即可。
git clone https://github.com/aliyun/aliyun-oss-c-sdk.git
CMakeList.txt开头增加
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/home/jw.li/work/toolchain-arm_cortex-a7+vfp_gcc-4.8-linaro_uClibc-0.9.33.2_eabi")
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-openwrt-linux-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-openwrt-linux-g++)
SET(CMAKE_SYSTEM_NAME Linux) 这句话一定要放到最前面,才会去找交叉编译工具
报错:
CMake Error at CMakeLists.txt:79 (MESSAGE):
Could not find apu-config/apu-1-config
修改CMakeList.txt 将apr 和apr-util bin文件目录加到下面语句中,否则编译cmake不过。
FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /home/jw.li/work/v50/osssdk/apr/bin/ /usr/bin /usr/local/bin /usr/local/apr/bin/)
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /home/jw.li/work/v50/osssdk/apr-util/bin/ /usr/bin /usr/local/bin /usr/local/apr/bin/)
cmake . -DCMAKE_INSTALL_PREFIX=/home/jw.li/work/v50/osssdk/oss_c_sdk -DCURL_INCLUDE_DIR=/home/jw.li/work/v50/osssdk/curl/include/ -DCURL_LIBRARY=/home/jw.li/work/v50/osssdk/curl/lib/libcurl.a -DAPR_INCLUDE_DIR=/home/jw.li/work/v50/osssdk/apr/include/apr-1/ -DAPR_LIBRARY=/home/jw.li/work/v50/osssdk/apr/lib/libapr-1.a -DAPR_UTIL_INCLUDE_DIR=/home/jw.li/work/v50/osssdk/apr-util/include/apr-1 -DAPR_UTIL_LIBRARY=/home/jw.li/work/v50/osssdk/apr-util/lib/libaprutil-1.a -DMINIXML_INCLUDE_DIR=/home/jw.li/work/v50/osssdk/mxml/include/ -DMINIXML_LIBRARY=/home/jw.li/work/v50/osssdk/mxml/lib/libmxml.a
make
make install
CFLAGS += -I$(INC_DIR)/include
CFLAGS += -I$(INC_DIR)/oss
CFLAGS += -I$(INC_DIR)/include/oss_c_sdk
CFLAGS += -I$(INC_DIR)/include/curl
CFLAGS += -I$(INC_DIR)/include/mxml
CFLAGS += -I$(INC_DIR)/include/apr-1
CFLAGS += -I$(INC_DIR)/include/apr-util/apr-1
LIBS+= -loss_c_sdk_static
LIBS+= -lcurl
LIBS+= -lapr-1
LIBS+= -lmxml
LIBS+= -laprutil-1
即
/home/jw.li/work/v50/osssdk/apr-util-1.5.4/xlate/xlate.c:75: undefined reference to `apr_os_locale_encoding'
/home/jw.li/work/v50/osssdk/apr-util-1.5.4/xlate/xlate.c:75: undefined reference to `apr_os_locale_encoding'
/home/jw.li/work/v50/osssdk/apr-util-1.5.4/xlate/xlate.c:72: undefined reference to `apr_os_default_encoding'
/home/jw.li/work/v50/osssdk/apr-util-1.5.4/xlate/xlate.c:72: undefined reference to `apr_os_default_encoding'
解决方案参见4.2