This topic describes how to install Object Storage Service (OSS) SDK for C++ and configure compilation options in different operating systems.

Prerequisites

  • A compiler that supports C++ 11 and later is installed.
  • Visual Studio 2013 or later is installed.
  • GCC 4.8 or later is installed.
  • Clang 3.3 or later is installed.

Download OSS SDK for C++

Install OSS SDK for C++

You can install OSS SDK for C++ in Linux, Windows, Android, and Mac.

  • In Linux:
    1. Install CMake and generate the build script for Linux.

      After you install CMake 3.1 or later, download the source code of SDK for C++ and generate the required file by using CMake.

      Run the following command to compile the source code:

      cd <path/to/aliyun-oss-cpp-sdk>
      mkdir build
      cd build
      cmake ..
    2. Install libcurl and openssl

      Run the following command to install RedHat or CentOS:

      yum –y install libcurl-devel openssl-devel

      Run the following command to install Fedora:

      sudo dnf install libcurl-devel openssl-devel
    3. Install the SDK.
      make && make install
    Notice By default, RTTI is disabled in OSS SDK for C++. Therefore, add the following options when you use g++ to install the SDK: -std=c++11, -fno-rtti, -lalibabacloud-oss-cpp-sdk, -lcurl, -lcrypto, and -lpthread.

    Examples:

    g++ test.cpp -std=c++11 -fno-rtti -lalibabacloud-oss-cpp-sdk -lcurl -lcrypto -lpthread -o test.bin
  • In Windows:
    1. Install CMake and generate the build script for Windows.

      After you install CMake 3.1 or later, open cmd and go to the directory of the SDK. Create a directory named build and then run the cmake .. command to generate required files. The following figure provides you an example on the process.

      cmake01
      Note
      • The SDK package does not include the project file alibabacloud-oss-cpp-sdk.sln. You must run the cmake command to generate required project files.
      • To build a x64 structure, run the cmake -A x64 .. command.
    2. Run VS developer command prompt as an administrator. Go to the build directory and run the following command to compile and install the SDK:
      msbuild ALL_BUILD.vcxproj
      msbuild INSTALL.vcxproj

      You can also use Visual Studio to open the project file alibabacloud-oss-cpp-sdk.sln to generate a solution.

  • In Android

    Build a project based on the android-ndk-r16 tool chain in Linux. Install third-party libraries libcurl and libopenssl in $ANDROID_NDK/sysroot and run the following command to compile and install the SDK:

    cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake  \
          -DANDROID_NDK=$ANDROID_NDK    \
          -DANDROID_ABI=armeabi-v7a     \
          -DANDROID_TOOLCHAIN=clang     \
          -DANDROID_PLATFORM=android-21 \
          -DANDROID_STL=c++_shared ..
    make
  • In macOS:

    In macOS, you can install dependency library by using the brew method.

    Specify the installation path of OpenSSL in Mac. For example, if OpenSSL is installed in /usr/local/Cellar/openssl/1.0.2p, run the following command to compile and install the SDK:

    cmake -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2p  \
          -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2p/lib  \
          -DOPENSSL_INCLUDE_DIRS=/usr/local/Cellar/openssl/1.0.2p/include/ ..
    make

Compilation options

You can configure different compilation options in different scenarios in the following format: cmake -D${OptionName}=ON|OFF ...

The following table describes the compilation options that you can configure.

Option Description
BUILD_SHARED_LIBS Build dynamic libraries. Default value: OFF. If you set this option to ON, dynamic libraries and static libraries are built at the same time, and the -static suffix is added to the name of static libraries.

To build dynamic libraries in the compilation, run the cmake -DBUILD_SHARED_LIBS=ON .. command.

ENABLE_RTTI Supports Run-Time Type Information. Default value: ON.
OSS_DISABLE_BUCKET Does not build interfaces related to buckets. Default value: OFF. You can set this option to ON to reduce code size.
OSS_DISABLE_LIVECHANNEL Does not build interfaces related to LivaChannels. Default value: OFF. You can set this option to ON to reduce code size.
OSS_DISABLE_RESUAMABLE Does not build interfaces related to resumable upload and download. Default value: OFF. You can set this option to ON to reduce code size.
OSS_DISABLE_ENCRYPTION Does not build interfaces related to client-side encryption. Default value: OFF. You can set this option to ON to reduce code size.