All Products
Search
Document Center

Object Storage Service:Installation

Last Updated:Dec 12, 2023

OSS SDK for C++ allows you to programmatically manage resources in Object Storage Service (OSS). For example, you can manage buckets, upload objects, download objects, and process images. This topic describes how to install C++ and configure compilation options in different operating systems.

Prerequisites

  • A compiler that supports C++ V11 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.

Linux

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

    1. Download the CMake installation package.

      CMake V3.21.1 is used as an example. You can install other versions based on your business requirements.

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

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

      cd cmake-3.21.1/
    4. Implement automated building and configurations, such as checking the system environment, generating Makefile files, and configuring compilation settings.

      ./bootstrap
    5. Compile the source code files one by one based on the rules specified in the Makefile file and generate executable files or library files.

      make
    6. Install the complied files.

      sudo make install
  2. Add environment variables.

    1. Edit the bash configuration file.

      vim .bashrc
    2. Configure environment variables.

      CMAKE_PATH=/usr/local/cmake
      export PATH=$CMAKE_PATH/bin:$PATH
    3. Run the following command for the changes to take effect:

      source .bashrc
    4. Query and display the path in which you can run the cmake command in the current system.

      which cmake
  3. Install dependencies.

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

    1. Download the OSS SDK for C++ package.

      wget -O aliyun-oss-cpp-sdk-master.zip "https://gosspublic.alicdn.com/doc/c-sdk/aliyun-oss-cpp-sdk-master.zip"
    2. Decompress the installation package.

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

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

      1. Create a directory to store files that are used for compiling and building the project.

        mkdir build
      2. Switch to the directory.

        cd build
      3. Create the project building system by using the CMake tool.

        cmake ..
      4. Compile the project.

        make
      5. Install the compiled files to the specified 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

    RTTI is disabled in OSS SDK for C++ by default. Therefore, add the following options when you use g++ to install OSS SDK for C++: -std=c++11, -fno-rtti, -lalibabacloud-oss-cpp-sdk, -lcurl, -lcrypto, and -lpthread.

Windows

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

    After CMake 3.1 or later is installed, open the Command Prompt and go to the directory that stores the SDK files. Create a directory named build, and run cmake .. to generate the required files. The following figure provides an example.

    cmake01

    Note
    • The OSS SDK for C++ package does not include the project file alibabacloud-oss-cpp-sdk.sln. You must run the cmake command to generate the required project files.

    • To build an 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 OSS SDK for C++:

    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.

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 OSS SDK for C++:

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

In macOS, you can install dependency libraries by using brew.

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 OSS SDK for C++:

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

Builds dynamic libraries. Default value: OFF. If you set this option to ON, both dynamic libraries and static libraries are built, and the -static suffix is added to the names of static libraries.

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

ENABLE_RTTI

Supports Run-Time Type Information. Default value: ON.

OSS_DISABLE_BUCKET

Specifies that bucket-related interfaces are not built. Default value: OFF. You can set this option to ON to reduce code size.

OSS_DISABLE_LIVECHANNEL

Specifies that LiveChanne-related interfaces are not built. Default value: OFF. You can set this option to ON to reduce code size.

OSS_DISABLE_RESUAMABLE

Specifies that interfaces related to resumable upload and download are not built. Default value: OFF. You can set this option to ON to reduce code size.

OSS_DISABLE_ENCRYPTION

Specifies that client-side encryption interfaces are not built. Default value: OFF. You can set this option to ON to reduce code size.