Install the OSS C SDK to manage OSS buckets, upload and download files, manage data, and process images. This topic describes how to install the OSS C SDK.
Prerequisites
Install the GCC and G++ compilers, version 4.8 or later, to support basic C99 and GNU99 syntax.
Background information
When you install the OSS C SDK, you must also install the CMake build tool and the third-party libraries curl, apr, apr-util, and minixml.
Name | Description | Version requirements |
CMake | Build tool. | 3.10.0 or later |
curl | Resolves network issues. | 7.32.0 or later |
apr-util | Handles memory management and cross-platform issues. | 1.5.2 or later |
minixml | Parses the XML returned by a request. | Version 2.9 is recommended. |
Install on Linux
Install CMake.
Red Hat/Alibaba Cloud/CentOS
sudo yum install cmakeUbuntu/Debian
sudo apt-get install cmakeSuSE
sudo zypper install cmakeInstall the third-party libraries.
Red Hat/Alibaba Cloud/CentOS
Install the curl library.
yum -y install libcurl-develInstall the apr library.
yum install apr-util yum install apr-devel yum install apr-util-develInstall the minixml library.
Download the minixml library.
wget "https://github.com/michaelrsweet/mxml/releases/download/release-2.9/mxml-2.9.tar.gz"Decompress the minixml library file.
tar zxf mxml-2.9.tar.gzNavigate to the folder.
cd mxml-2.9Compile and install the minixml library.
./configure make sudo make install
Ubuntu/Debian
sudo apt-get install libcurl4-openssl-dev libapr1-dev libaprutil1-dev libmxml-devSuSE
sudo zypper install libcurl-devel libapr1-devel libapr-util1-devel mxml-develInstall the C SDK.
Download the OSS C SDK source package.
The following example uses version 3.10.0. For the download link, see GitHub.
Decompress the package.
tar zxf aliyun-oss-c-sdk-3.10.0.tar.gzNavigate to the folder.
cd aliyun-oss-c-sdk-3.10.0Install the C SDK.
cmake . make sudo make installIf the curl, apr, apr-util, and mxml third-party libraries are not installed in the default path, you must specify their installation paths when you install the SDK.
cmake -f CMakeLists.txt // The build type is Release. Common build types are Debug, Release, RelWithDebInfo, and MinSizeRel. The default is Debug. -DCMAKE_BUILD_TYPE=Release // Custom installation folder. -DCMAKE_INSTALL_PREFIX=/usr/local/ // Specify the folders where the header files and library files of the curl, apr, apr-util, and xml third-party libraries are located. -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 // If the "Could not find apr-config/apr-1-config" error is reported during compilation, it is because the apr-1-config file cannot be found in the default path. Add this option. -DAPR_CONFIG_BIN=/path/to/bin/apr-1-config // If the "Could not find apu-config/apu-1-config" error is reported during compilation, it is because the apu-1-config file cannot be found in the default path. Add this option. -DAPU_CONFIG_BIN=/path/to/bin/apu-1-config
Compile the sample project.
Download 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.gzDecompress the sample project.
tar zxf aliyun-oss-c-sdk-demo.tar.gzNoteWhen you install oss-c-sdk-demo-specified-installation, you must specify the installation folder, such as **/home/your/oss/csdk**. Other sample projects use the default installation paths of the OSS C SDK and its dependency libraries, so you do not need to specify an installation folder. For more information about installing the sample project, see Use the Alibaba Cloud OSS C SDK on Linux.
Compile the sample project.
Navigate to the project folder (oss-c-sdk-demo-xxx).
Run
maketo compile the sample project.NoteReplace OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, and BUCKET_NAME in the sample code with valid values. If the dynamic libraries for the OSS C SDK and its dependencies are not in a system library path, use
LD_LIBRARY_PATHto specify their location when you run the program.Run
./mainto run the executable program.To recompile, run
make clean.
Install on Windows
Download and install the OSS C SDK.
Download and decompress the sample project.
Use Visual Studio to compile the sample project.
If you use Visual Studio 2012 or a later version, you are prompted to upgrade the project to use the latest compiler and libraries. We recommend that the editor and library versions match your project version. If your project is compatible with the latest compiler and libraries, click Upgrade. Otherwise, do not upgrade.
Before you compile the sample project, replace OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, BUCKET_NAME, OBJECT_NAME, MULTIPART_UPLOAD_FILE_PATH, and DIR_NAME in oss_config.c with valid values.
For detailed steps and frequently asked questions (FAQ) about using Visual Studio to run the sample project, see Compile and use the Alibaba Cloud OSS C SDK on Windows.