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
Install CMake and use it to generate build scripts for the target platform.
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.gzDecompress the CMake installation package file.
tar xvf cmake-3.21.1.tar.gzGo to the CMake installation folder.
cd cmake-3.21.1/Run the automated build and configuration process to check the system environment, generate Makefile files, and configure compilation options.
./bootstrapCompile the source code based on the rules in the Makefile to generate the target executable or library files.
makeInstall the compiled files.
sudo make install
Add environment variables.
Edit the bash configuration file.
vim .bashrcConfigure the environment variables.
CMAKE_PATH=/usr/local/cmake export PATH=$CMAKE_PATH/bin:$PATHApply the changes to the bash configuration file.
source .bashrcDisplay the path of the
cmakecommand executable file.which cmake
Install dependencies.
yum -y install libcurl-devel openssl-devel unzipInstall the C++ SDK.
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"Decompress the installation package file.
unzip aliyun-oss-cpp-sdk-master.zipGo to the installation folder.
cd aliyun-oss-cpp-sdk-masterInstall the C++ SDK.
Create a build folder for the project.
mkdir buildSwitch to the build folder.
cd buildUse CMake to generate the project build system.
cmake ..Compile the project.
makeInstall the compiled files to the specified system directory.
make install
Compile the sample file.
g++ test.cpp -std=c++11 -fno-rtti -lalibabacloud-oss-cpp-sdk -lcurl -lcrypto -lpthread -o test.binImportantThe 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
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.
NoteThe 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.
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.vcxprojAlternatively, 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 ..
makemacOS
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/ ..
makeCompilation 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. |