All Products
Search
Document Center

Object Storage Service:Installation (C++ SDK)

Last Updated:Nov 29, 2025

To manage OSS buckets, upload and download files, manage data, or process images, you must install the OSS C++ SDK. This topic describes how to install the OSS C++ SDK on different operating systems and how to use compilation options.

Prerequisites

  • A compiler that supports C++11 or later

  • Visual Studio 2013 or later

  • GCC 4.8 or later

  • Clang 3.3 or later

Download the SDK

Install the SDK

You can install the SDK on Linux, Windows, Android, and macOS.

Linux

  1. Install CMake and use it to generate build scripts for the target platform.

    1. Download the CMake installation package.

      The following steps use CMake 3.21.1 as an example. To download another version, you can replace the version number as needed.

      wget https://cmake.org/files/v3.21/cmake-3.21.1.tar.gz
    2. Decompress the CMake installation package file.

      tar xvf cmake-3.21.1.tar.gz
    3. Go to the CMake installation folder.

      cd cmake-3.21.1/
    4. Run the automated build and configuration process to check the system environment, generate Makefile files, and configure compilation options.

      ./bootstrap
    5. Compile the source code based on the rules in the Makefile to generate the target executable or library files.

      make
    6. Install the compiled files.

      sudo make install
  2. Add environment variables.

    1. Edit the bash configuration file.

      vim .bashrc
    2. Configure the environment variables.

      CMAKE_PATH=/usr/local/cmake
      export PATH=$CMAKE_PATH/bin:$PATH
    3. Apply the changes to the bash configuration file.

      source .bashrc
    4. Display the path of the cmake command executable file.

      which cmake
  3. Install dependencies.

    yum -y install libcurl-devel openssl-devel unzip
  4. Install the C++ SDK.

    1. Download the C++ SDK installation package.

      wget -O aliyun-oss-cpp-sdk-master.zip "https://github.com/aliyun/aliyun-oss-cpp-sdk/archive/refs/tags/1.10.0.zip"
    2. Decompress the installation package file.

      unzip aliyun-oss-cpp-sdk-master.zip
    3. Go to the installation folder.

      cd aliyun-oss-cpp-sdk-master
    4. Install the C++ SDK.

      1. Create a build folder for the project.

        mkdir build
      2. Switch to the build folder.

        cd build
      3. Use CMake to generate the project build system.

        cmake ..
      4. Compile the project.

        make
      5. Install the compiled files to the specified system directory.

        make install
  5. Compile the sample file.

    g++ test.cpp -std=c++11 -fno-rtti -lalibabacloud-oss-cpp-sdk -lcurl -lcrypto -lpthread -o test.bin
    Important

    The C++ SDK disables the RTTI property by default. Therefore, when you use g++ to compile the runtime, you must add the -std=c++11, -fno-rtti, -lalibabacloud-oss-cpp-sdk, -lcurl, -lcrypto, and -lpthread options.

Windows

  1. Install CMake and use it to generate build scripts for the target platform.

    After you install CMake 3.1 or later, open the cmd command prompt, navigate to the SDK folder, create a build folder, and run cmake .. to generate the required files. The following figure shows an example.

    cmake01

    Note
    • The SDK package does not provide the alibabacloud-oss-cpp-sdk.sln project file. You must generate the required project file using the cmake command.

    • To build for the x64 architecture, use the cmake -A x64 .. command.

  2. Open the VS developer command prompt as an administrator. In the build folder, run the following commands to compile and install the SDK.

    msbuild ALL_BUILD.vcxproj
    msbuild INSTALL.vcxproj

    Alternatively, you can open the alibabacloud-oss-cpp-sdk.sln file in Visual Studio to build the solution.

Android

In a Linux environment, build the project using the android-ndk-r16 toolchain. You must install the libcurl and libopenssl dependency libraries in the $ANDROID_NDK/sysroot path, and then run the following commands 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

macOS

On macOS, you can use brew to install dependency libraries.

On macOS, you must specify the OpenSSL installation path. For example, if OpenSSL is installed in the /usr/local/Cellar/openssl/1.0.2p folder, run the following commands 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 set different compilation options for specific scenarios. The format for compilation options is cmake -D${OptionName}=ON|OFF ...

The following table describes the available compilation options.

Option name

Description

BUILD_SHARED_LIBS

Builds a dynamic library. The default value is OFF. When this option is enabled, both static and dynamic libraries are built, and the -static suffix is added to the name of the static library.

To build a dynamic library, use the cmake -DBUILD_SHARED_LIBS=ON .. command.

ENABLE_RTTI

Supports Run-Time Type Information (RTTI). The default value is ON.

OSS_DISABLE_BUCKET

Does not build Bucket-related setting interfaces. The default value is OFF. To reduce the code size, set this option to ON.

OSS_DISABLE_LIVECHANNEL

Does not build LiveChannel interfaces. The default value is OFF. To reduce the code size, set this option to ON.

OSS_DISABLE_RESUAMABLE

Does not build resumable transfer interfaces. The default value is OFF. To reduce the code size, set this option to ON.

OSS_DISABLE_ENCRYPTION

Does not build client-based encryption interfaces. The default value is OFF. To reduce the code size, set this option to ON.