OSS_SDK transplantation on HiSilicon platform

Introduction to Alibaba Cloud OSS

Alibaba Cloud Object Storage Service (OSS) is a massive, secure, low-cost, and highly durable cloud storage service provided by Alibaba Cloud.


Aliyun OSS official address c_sdk:
https://github.com/aliyun/aliyun-oss-c-sdk
cpp_sdk:
https://github.com/aliyun/aliyun-oss-cpp-sdk
Related dependent libraries:
Libcurl
Apr
apr -util
minixml
openssl
I organized and packaged one myself, and I can download it directly
https://download.csdn.net/download/weixin_43817380/13077093

1 mxmlv2.10

Download address:
https://github.com/michaelrsweet/mxml/releases
Create a cross.sh file, copy the following, modify the relevant directory to execute, and then make and make install can be installed to the directory specified by –prefix.

  • –Prefix: The installation directory is the directory where the include lib is located after make install. (The same will not be said later)
  • --Host: the platform the software will run on (can be set at will)
  • CC: cross-compiled gcc tool
  • CXX: cross-compiled g++ tool
./configure                           \
--prefix=/home/dl/OSS/libmxml          \
-host=arm-linux                        \
CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc   \
CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++

Execute the sh cross.sh command. After the configuration is successful,
execute make and make install.

2 libcurl library

Source code: https://curl.haxx.se/download.html

./configure \
--prefix=/home/dl/OSS/libcurl \
--host=arm-linux \
CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc   \
CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++

Execute the sh cross.sh command. After the configuration is successful,
execute make and make install.

3 apr-1.7.0

Download address https://apr.apache.org/

./configure --prefix=/home/dl/OSS/libapr \
--host=arm-linux CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc \
CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-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 \
APR_HAS_PROC_PTHREAD_SERIALIZE=yes

Execute sh cross.sh, make, and make install to
execute make after running, and an error will occur

3.1 Error. /include/apr_want.h:94:8: error: redefinition of'struct iovec'

Modify the apr_want.h file. Start from line 92

#ifndef APR_IOVEC_DEFINED
#define APR_IOVEC_DEFINED
  struct iovec
 {
    
    
 void *iov_base;
  size_t iov_len;
  };  
  #endif /* !APR_IOVEC_DEFINED */

Comment out this paragraph

3.2 报错encoding/apr_escape.c:79:33: error: ‘test_char_table’ undeclared

Found on line 134 in makeflie

OBJECTS_gen_test_char = tools/gen_test_char.lo $(LOCAL_LIBS)

Block it

Or put in the ./encoding/apr_escape.c file

 #define TEST_CHAR(c, f)        (test_char_table[(unsigned)(c)] & (f))

Definition changed to empty

3.3报错locks/unix/proc_mutex.c:1494:28: error: ‘mutex_proc_pthread_methods’ undeclared (first use in this function)

Go to line 255 in the apr.h file

#define APR_HAS_PROC_PTHREAD_SERIALIZE    0

To

#define APR_HAS_PROC_PTHREAD_SERIALIZE    1

Save, then make, make install

4 apr-util-1.5.4

The download address is the same as apr: https://apr.apache.org/
libexpat needs to be compiled before compilation

4.1 Cross compilation of libexpat

Download address https://github.com/libexpat/libexpat,
enter the libexpat-master/expat directory, and create a cross.sh file

./configure --prefix=/home/dl/OSS/libexpat   \
-host=arm-linux \
CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc

Execute sh cross.sh, make, make install

4.2 Cross compilation of apr-util 1.5.4

Create cross.sh file

./configure \
CC=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-gcc \
CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++ --host=arm-linux  \
--prefix=/home/dl/OSS/libaprutil \
--with-apr=/home/dl/OSS/libapr \
--with-expat=/home/dl/OSS/libexpat 

Among them --with-apr is the installation directory after compiling apr before
–with-expatr is the installation directory
make after compiling expat before , just make install

5 Cross compilation of openssl 1.1.1c

Download
link https://www.openssl.org/source/ Create cross.sh file and add the following content

./config no-asm shared no-async \
--prefix=/home/dl/OSS/libssl \
--cross-compile-prefix=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-

Configure sudo make, it will prompt error

5.1 Error prompt arm-himix200-linux-gcc: error: unrecognized command line option'-m64'

Open the Makefile, search for -m64, and find it on line 124

CNF_CPPFLAGS=-DNDEBUG
CNF_CFLAGS=-pthread -m64
CNF_CXXFLAGS=-std=c++11 -pthread -m64
CNF_LDFLAGS=
CNF_EX_LIBS=-ldl -pthread

Delete the -m64 option, sudo make, sudo make install

6 Cross compilation of aliyun-oss-cpp-sdk

Create cross.sh file and add script

cmake . -DCMAKE_INSTALL_PREFIX=/home/dl/OSS/OSS_sdk \
-DCURL_INCLUDE_DIR=/home/dl/OSS/libcurl/include/  \
-DCURL_LIBRARY=/home/dl/OSS/libcurl/lib/libcurl.a  \
-DAPR_INCLUDE_DIR=/home/dl/OSS/libapr/include/apr-1/  \
-DAPR_LIBRARY=/home/dl/OSS/libapr/lib/libapr-1.a   \
-DAPR_UTIL_INCLUDE_DIR=/home/dl/OSS/libaprutil/include/apr-1   \
-DAPR_UTIL_LIBRARY=/home/dl/OSS/libaprutil/lib/libaprutil-1.a \
-DMINIXML_INCLUDE_DIR=/root/libmxml/include/  \
-DMINIXML_LIBRARY=/home/dl/OSS/libmxml/lib/libmxml.a  \
-DOPENSSL_INCLUDE_DIR=/home/dl/OSS/libssl/include  \
-DOPENSSL_LIBRARY=/home/dl/OSS/libssl/lib

-DCMAKE_INSTALL_PREFIX is the path of OSS installation. The following are the paths of previously compiled libraries (except openssl). Openssl should be modified after entering CMakeLists.txt.
Open CMakeLists.txt and add it at the top of the file

SET(CMAKE_SYSTEM_NAME Linux)
#这一句一定要放在最前面
cmake_minimum_required(VERSION 3.1)
#########

SET(TOOLCHAIN_DIR "/opt/hisi-linux/x86-arm/arm-himix200-linux")
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}/host_bin/arm-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/host_bin/arm-linux-gnueabi-g++)

#下面这些注意修改对应的路径
FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /home/dl/OSS/libapr/bin /usr/bin /usr/local/bin /usr/local/apr/bin/)
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /home/dl/OSS/libaprutil/bin /usr/bin /usr/local/bin /usr/local/apr/bin/)
#接着向下走 #curl-config时添加
FIND_PROGRAM(CURL_CONFIG_BIN NAMES curl-config PATH /home/dl/OSS/libcurl/bin )

At this time, there is no link to the openssl library, and
then find include(FindOpenSSL)and `

	if(NOT OPENSSL_FOUND)
		message(FATAL_ERROR "Could not find openssl")
	endif()

Part, comment out, add

	include_directories(/home/dl/OSS/libssl/include)
	FIND_LIBRARY(OPENSSL_LIB  /home/dl/OSS/libssl/lib NO_DEFAULT_PATH)

Then you need to pull down to the end to find

if(BUILD_SAMPLE)
	add_subdirectory(sample)
endif()

if(BUILD_TESTS)
	add_subdirectory(test)
	add_subdirectory(ptest)
endif()

Comment out all,
save the changes and sudo sh cross.sh
then sudo make, sudo make install

Finally, attach my modified CMakeList.txt

#
# Copyright 2009-2017 Alibaba Cloud All rights reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
SET(CMAKE_SYSTEM_NAME Linux)
cmake_minimum_required(VERSION 3.1)


#########
SET(CMAKE_SYSTEM_NAME Linux)
SET(TOOLCHAIN_DIR "/opt/hisi-linux/x86-arm/arm-himix200-linux")
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}/host_bin/arm-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/host_bin/arm-linux-gnueabi-g++)
#SET(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/aarch64-linux-gnu-gcc)
#SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/aarch64-linux-gnu-g++)

FIND_PROGRAM(APR_CONFIG_BIN NAMES apr-config apr-1-config PATHS /home/dl/OSS/libapr/bin /usr/bin /usr/local/bin /usr/local/apr/bin/)
FIND_PROGRAM(APU_CONFIG_BIN NAMES apu-config apu-1-config PATHS /home/dl/OSS/libaprutil/bin /usr/bin /usr/local/bin /usr/local/apr/bin/)
#接着向下走 #curl-config时添加
FIND_PROGRAM(CURL_CONFIG_BIN NAMES curl-config PATH /home/dl/OSS/libcurl/bin )

cmake_policy(SET CMP0048 NEW)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#Project setting
file(STRINGS "VERSION" version)
project(alibabacloud-oss-cpp-sdk VERSION ${version})
message(STATUS "Project version: ${PROJECT_VERSION}")
set(SDK_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
set(TARGET_OUTPUT_NAME_PREFIX "alibabacloud-oss-" CACHE STRING "The target's output name prefix")

######


#Options
option(BUILD_SHARED_LIBS  "Enable shared library" OFF)
#option(BUILD_SAMPLE "Build sample" ON)
#如果不想编译例程和测试的文件,也可以在这里设置为OFF
option(BUILD_SAMPLE "Build sample" OFF)

option(BUILD_TESTS "Build unit and perfermence tests" OFF)
option(ENABLE_COVERAGE "Flag to enable/disable building code with -fprofile-arcs and -ftest-coverage. Gcc only" OFF)
option(ENABLE_RTTI "Flag to enable/disable building code with RTTI information" ON)
#############################
#如果提示Do not support target platform就把这一段全都注释掉
############################
#Platform
# if (CMAKE_CROSSCOMPILING)
# 	if (${CMAKE_SYSTEM_NAME} STREQUAL "Android")
# 		set(PLATFORM_ANDROID 1)
# 		set(TARGET_OS "ANDROID")
# 	else()
# 		message(FATAL_ERROR "Do not support target platform")
# 	endif()
# else()
# 	if(CMAKE_HOST_APPLE)
# 		set(PLATFORM_APPLE 1)
# 		set(TARGET_OS "APPLE")
# 	elseif(CMAKE_HOST_UNIX)
# 		set(PLATFORM_LINUX 1)
# 		set(TARGET_OS "LINUX")
# 	elseif(CMAKE_HOST_WIN32)
# 		set(PLATFORM_WINDOWS 1)
# 		set(TARGET_OS "WINDOWS")
# 	else()
# 		message(FATAL_ERROR "Do not support unknown host OS")
# 	endif()
# endif()

# set(PLATFORM_LINUX 1)
# set(TARGET_OS "LINUX")

message(STATUS "TARGET_OS: ${TARGET_OS}")

add_definitions(-DPLATFORM_${TARGET_OS})

#######################
#如果一直提示不正确的if参数,就仿照我这样注释掉他们
#######################
#Find dependency Library, curl, openssl
# if (${TARGET_OS} STREQUAL "WINDOWS")
# 	set(WLIB_TARGET "Win32")
# 	if (CMAKE_CL_64)
# 	set(WLIB_TARGET "x64")
# 	endif()
# 	set(CRYPTO_LIBS 
# 		${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/ssleay32.lib)
# 		${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libeay32.lib)
# 	set(CRYPTO_INCLUDE_DIRS 
# 		${CMAKE_SOURCE_DIR}/third_party/include) 

# 	set(CLIENT_LIBS 
# 		${CMAKE_SOURCE_DIR}/third_party/lib/${WLIB_TARGET}/libcurl.lib) 
# 	set(CLIENT_INCLUDE_DIRS 
# 		${CMAKE_SOURCE_DIR}/third_party/include) 
# else()
	#include(FindCURL)
	#include(FindOpenSSL)
 
	#if(NOT CURL_FOUND)
	#	message(FATAL_ERROR "Could not find curl")
	#endif()
	######################
	#很奇怪我一直提示找不到CURL的库,只好这么加入了CURL的路径和库
	include_directories(/home/dl/OSS/libcurl/include)
	FIND_LIBRARY(CURL_LIB  /home/dl/OSS/libcurl/lib NO_DEFAULT_PATH)
	include_directories(/home/dl/OSS/libssl/include)
	FIND_LIBRARY(OPENSSL_LIB  /home/dl/OSS/libssl/lib NO_DEFAULT_PATH)
	######################
	# if(NOT OPENSSL_FOUND)
	# 	message(FATAL_ERROR "Could not find openssl")
	# endif()

	set(CRYPTO_LIBS ${OPENSSL_LIBRARIES})
	set(CRYPTO_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIRS}) 
	set(CRYPTO_LIBS_ABSTRACT_NAME crypto ssl)

	set(CLIENT_LIBS ${CURL_LIBRARIES})
	set(CLIENT_INCLUDE_DIRS ${CURL_INCLUDE_DIRS}) 
	set(CLIENT_LIBS_ABSTRACT_NAME curl)
# endif()

#Compiler flags
list(APPEND SDK_COMPILER_FLAGS "-std=c++11")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
	list(APPEND SDK_COMPILER_FLAGS "/MP")
	if (NOT ENABLE_RTTI)
	list(APPEND SDK_COMPILER_FLAGS "/GR-")
	endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
	list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC" "-fno-rtti")
	if (NOT ENABLE_RTTI)
	list(APPEND SDK_COMPILER_FLAGS "-fno-rtti")
	endif()
	
	list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
else()
	list(APPEND SDK_COMPILER_FLAGS "-fno-exceptions" "-fPIC")
	if (NOT ENABLE_RTTI)
	list(APPEND SDK_COMPILER_FLAGS "-fno-rtti")
	endif()
	
	list(APPEND SDK_COMPILER_FLAGS "-Wall" "-Werror" "-pedantic" "-Wextra")
	
	if (ENABLE_COVERAGE)
	SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
	SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
	SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
	endif()
endif()


if (BUILD_SHARED_LIBS)
	set(STATIC_LIB_SUFFIX "-static")
else()
	set(STATIC_LIB_SUFFIX "")
endif()

include(ExternalProject)
include(GNUInstallDirs)

add_subdirectory(sdk)

if(BUILD_SAMPLE)
#	add_subdirectory(sample)
endif()

if(BUILD_TESTS)
#	add_subdirectory(test)
#	add_subdirectory(ptest)
endif()

Guess you like

Origin blog.csdn.net/weixin_43817380/article/details/109366943