All Products
Search
Document Center

Object Storage Service:Use OSS SDK for C on Ubuntu for cross-compilation

Last Updated:Mar 01, 2023

Overview

This topic describes how to use Object Storage Service (OSS) SDK for C on Ubuntu for cross-compilation.

Introduction and procedure

Introduction

Cross-compilation: An executable file is generated on one platform that can run on another platform. For example, an executable file is generated on Linux that can run on Windows. In this example, an executable file is generated on Linux that can run on the ARM development environment. Compilation is different from cross-compilation. In compilation, an executable file that can run on the compilation platform is generated.

Prepare the installation environment

  1. Download the arm-linux-gcc cross-compiler.

  2. Download OSS SDK for C. For download URL, see Preface.

  3. Download the APR and APR-util source code from the Apache official website.

  4. Download the cURL source code from the cURL official website.

  5. Download the MXML source code of version 2.9.1 from the SourceForge official website.

  6. Download the expat source code from the expat official website.

Installation

Install arm-linux-gcc

  1. Log on to a server and run the following command to create a /usr/local/arm_4.4.3 directory:

    mkdir /usr/local/arm_4.4.3

  2. Run the following command to decompress the cross-compiler:

    tar zvxf arm-linux-gcc-4.4.3.tar.gz

  3. Run the following command to copy all files of the cross-compiler to the /usr/local/arm_4.4.3 directory:

    mv opt/FriendlyARM/toolschain/4.4.3/*  /usr/local/arm_4.4.3

  4. Modify the environment variable and add the following content to the end of the /etc/profile file:

    export PATH=$PATH:/usr/local/arm_4.4.3/bin/

  5. Run the following command to load the new environment variable configurations:

    source /etc/profile

  6. Run the following command to check whether arm-linux-gcc is installed:

    arm-linux-gcc -V

    A command output that is similar to the following information is displayed:

Install the cURL library

  1. After you decompress the cURL source code, run the following command to configure the cURL library:

    ./configure --prefix=/root/curl --host=arm-none-linux CC=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-g++
    Note

    Note: The cURL library is installed in the /root/curl directory.

  2. Run the following commands to compile the cURL library:

    make 
    make install
    make clean

Install the APR library

  1. Run the following command to configure the APR library:

    ./configure --prefix=/root/apr-1/ --host=arm-none-linux CC=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-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
    Note

    Note: The APR library is installed in the /root/apr-1 directory.

    If the following error is reported during installation, define the I/O vector structure.

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

    The definition of the I/O vector structure is shown in the following figure.

  2. Run the make command. If the following error is reported, perform the following operations. If no error is reported, run the make install command.

    encoding/apr_escape.c:79:33: error: 'test_char_table' undeclared
    tools/gen_test_char > include/private/apr_escape_test_char.h
    /bin/bash: tools/gen_test_char: cannot execute binary file: Exec format error

  3. Run the following command in sequence to generate a gen_test_char file that runs on the current platform:

    gcc -Wall -O2 -DCROSS_COMPILE tools/gen_test_char.c -s -o gen_test_char
    ./gen_test_char > include/private/apr_escape_test_char.h

  4. Modify the MakeFile file in the current directory to prevent the automatic generation of the gen_test_char file.

  5. Run the following command to re-install the APR library:

    make
    make install
    make clean

Install the Expat library

  1. If you directly install the APR-util library, the following error occurs. You must install the Expat library first because the XML parser does not exist.

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

  2. Run the following command to decompress the Expat package:

    bzip2 -d expat-2.2.5.tar.bz2
    tar vxf expat-2.2.5.tar

  3. Run the following command to access the specified directory:

    cd expat-2.2.5/

  4. Run the following command to configure the Expat library:

    ./configure --prefix=/root/expat --host=arm-none-linux CC=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-g++
    Note

    Note: Install the Expat library in the /root/expat directory.

Install the APR-util library

Run the following command to configure the APR-util library:

./configure --prefix=/root/apr-util --host=arm-none-linux CC=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-g++ --with-apr=/root/apr-1 --with-expat=/root/expat

Install the libmxml library

  1. Run the following command to decompress the libmxml package:

    tar zvxf libmxml-0.9.1.tar.gz

  2. Run the following command to access the specified directory:

    cd libmxml-0.9.1/

  3. Run the following command to create the libmxml directory:

    mkdir /root/libmxml

  4. Run the following command to install the libmxml library:

    ./configure --prefix=/root/libmxml --host=arm-none-linux CC=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-gcc CXX=/usr/local/arm_4.4.3/bin/arm-none-linux-gnueabi-g++

Install OSS SDK for C

  1. Run the following command to decompress the installation package of OSS SDK for C:

    tar zvxf aliyun-oss-c-sdk-3.5.0.tar.gz

  2. Run the following command to access the specified directory:

    cd aliyun-oss-c-sdk-3.5.0

  3. Modify the CMakeList.txt file and add the path of the cross-compiler to the start of the file:

  4. Change the retrieval path for apr-1 and APR-util configurations:

  5. Go to the oss_c_sdk_test and oss_c_sdk_sample directories, and modify the following CMakeList.txt files.

  6. Run the following installation command:

    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/local/arm_4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libpthread.a -DMATH_LIBRARY=/usr/local/arm_4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/libm.a -DRT_LIBRARY=/usr/local/arm_4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/librt.a
    Note

    Note: The cross-compiler and installation paths of several third-party libraries in the preceding screenshot are executed in this command. The system library path must also reference the system library path of the cross-compiler.

  7. Run the following command to compile OSS SDK for C:

    make
    make install
    make clean

Supported scope

  • OSS