Install the OSS C SDK to manage buckets, upload and download objects, and process images.
On this page
Prerequisites
Before you begin, ensure that you have:
GCC and G++ compilers, version 4.8 or later (required for C99 and GNU99 syntax support)
Dependencies
The OSS C SDK requires CMake and three third-party libraries. Install these before building the SDK.
| Dependency | Purpose | Version |
|---|---|---|
| CMake | Build tool | 3.10.0 or later |
| curl | Network communication | 7.32.0 or later |
| apr-util | Memory management and cross-platform support | 1.5.2 or later |
| minixml | Parses XML responses | 2.9 (recommended) |
Install on Linux
Step 1: Install CMake
Run the command for your distribution:
Ubuntu/Debian
sudo apt-get install cmakeRed Hat/Alibaba Cloud Linux/CentOS
sudo yum install cmakeSuSE
sudo zypper install cmakeStep 2: Install the dependency libraries
Run the commands for your distribution:
Ubuntu/Debian
Install all dependency libraries with a single command:
sudo apt-get install libcurl4-openssl-dev libapr1-dev libaprutil1-dev libmxml-devRed Hat/Alibaba Cloud Linux/CentOS
Install curl:
yum -y install libcurl-develInstall apr and apr-util:
yum install apr-util yum install apr-devel yum install apr-util-develInstall minixml from source:
wget "https://github.com/michaelrsweet/mxml/releases/download/release-2.9/mxml-2.9.tar.gz" tar zxf mxml-2.9.tar.gz cd mxml-2.9 ./configure make sudo make install
SuSE
sudo zypper install libcurl-devel libapr1-devel libapr-util1-devel mxml-develStep 3: Install the SDK
The following example uses OSS C SDK version 3.10.0. For the latest release, see GitHub.
Download and decompress the SDK source package:
tar zxf aliyun-oss-c-sdk-3.10.0.tar.gz cd aliyun-oss-c-sdk-3.10.0Build and install:
cmake . make sudo make install
Custom installation paths
If curl, apr, apr-util, or minixml are installed in non-default locations, specify their paths during the build. Replace the paths below with the actual locations on your system:
cmake -f CMakeLists.txt \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DCURL_INCLUDE_DIR=/usr/include/curl \
-DCURL_LIBRARY=/usr/lib64/libcurl.so \
-DAPR_INCLUDE_DIR=/usr/include/apr-1 \
-DAPR_LIBRARY=/usr/lib64/libapr-1.so \
-DAPR_UTIL_INCLUDE_DIR=/usr/include/apr-1 \
-DAPR_UTIL_LIBRARY=/usr/lib64/libaprutil-1.so \
-DMINIXML_INCLUDE_DIR=/usr/include \
-DMINIXML_LIBRARY=/usr/lib64/libmxml.so-DCMAKE_BUILD_TYPE accepts Debug, Release, RelWithDebInfo, and MinSizeRel. The default is Debug.
Step 4: Compile and run the sample project
Download and decompress the sample project:
wget https://docs-aliyun.cn-hangzhou.oss.aliyun-inc.com/assets/attach/32132/cn_zh/1487730555529/aliyun-oss-c-sdk-demo.tar.gz tar zxf aliyun-oss-c-sdk-demo.tar.gzOpen the sample code and replace the placeholder values:
Placeholder Description OSS_ENDPOINTYour OSS endpoint, for example https://oss-cn-hangzhou.aliyuncs.comACCESS_KEY_IDYour AccessKey ID ACCESS_KEY_SECRETYour AccessKey Secret BUCKET_NAMEThe name of your bucket NoteWhen installing
oss-c-sdk-demo-specified-installation, specify the installation directory, for example/home/your/oss/csdk. Other sample projects use the default installation paths and do not require a custom directory. For detailed steps, see Use the Alibaba Cloud OSS C SDK on Linux.Navigate to the project directory (
oss-c-sdk-demo-xxx) and compile:makeRun the sample:
./mainTo recompile from scratch, run
make cleanfirst.NoteIf the OSS C SDK dynamic libraries or their dependency libraries are not in a system library path, set
LD_LIBRARY_PATHto their location before running the program.
Install on Windows
Download the OSS C SDK:
Download the sample project:
Open
oss_config.cand replace the following placeholders with valid values:OSS_ENDPOINT,ACCESS_KEY_ID,ACCESS_KEY_SECRET,BUCKET_NAME,OBJECT_NAME,MULTIPART_UPLOAD_FILE_PATH, andDIR_NAME.Use Visual Studio 2012 or later to compile the sample project. For detailed steps and frequently asked questions, see Compile and use the Alibaba Cloud OSS C SDK on Windows.
NoteVisual Studio may prompt you to upgrade the project to use the latest compiler and libraries. Match the editor and library versions to your project version. If your project is compatible with the latest compiler and libraries, click Upgrade. Otherwise, skip the upgrade.
Troubleshooting
`Could not find apr-config/apr-1-config`
The apr-1-config binary is not in the default path. Add the following flag to your cmake command:
-DAPR_CONFIG_BIN=/path/to/bin/apr-1-config`Could not find apu-config/apu-1-config`
The apu-1-config binary is not in the default path. Add the following flag to your cmake command:
-DAPU_CONFIG_BIN=/path/to/bin/apu-1-config