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 OSS SDK for C.
Prerequisites
GCC and G++ compilers of the latest versions are installed.
Background information
When you install OSS SDK for C on Linux, you must install CMake and the following third-party libraries: cURL, APR, APR-util, and Mini-XML.
Item | Description | Version |
CMake | Manages the build process of software by using a compiler-independent method. | 2.6.0 or later |
curl | Resolves network issues. | 7.32.0 or later |
apr-util | Manages memory and portability between different platforms. | 1.5.2 or later |
minixml | Parses the XML data returned by a request. | 2.9 (recommended) |
Install OSS SDK for C on Linux
Install CMake.
RedHat/Aliyun/CentOS
sudo yum install cmake
Ubuntu/Debian
sudo apt-get install cmake
SuSE
sudo zypper install cmake
Install the third-party libraries.
RedHat/Aliyun/CentOS
Install the curl library.
yum -y install libcurl-devel
Install the apr library.
yum install apr-util yum install apr-devel yum install apr-util-devel
Install 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.gz
Go to the directory.
cd mxml-2.9
Compile and install the minixml library.
./configure make sudo make install
Ubuntu/Debian
sudo apt-get install libcurl4-openssl-dev libapr1-dev libaprutil1-dev libmxml-dev
SuSE
sudo zypper install libcurl-devel libapr1-devel libapr-util1-devel mxml-devel
Install OSS SDK for C.
Download the source code package.
The following sample code uses V3.10.0 as an example. For more information, visit GitHub.
Decompress the package.
tar zxf aliyun-oss-c-sdk-3.10.0.tar.gz
Go to the directory.
cd aliyun-oss-c-sdk-3.10.0
Install OSS SDK for C.
cmake . make sudo make install
If you want to install third-party libraries cURL, APR, APR-util, and Mini-XML in a custom installation path, run the following commands to install OSS SDK for C:
cmake -f CMakeLists.txt // Set the build type to Release. Typical build types include Debug, Release, RelWithDebInfo, and MinSizeRel. By default, Debug is used. -DCMAKE_BUILD_TYPE=Release // Specify a path to install OSS SDK for C. -DCMAKE_INSTALL_PREFIX=/usr/local/ // Specify the path in which third-party libraries cURL, APR, APR-util, and Mini-XML are installed. -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, the apr-1-config file does not exist in the default path. Add the following 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, the apu-1-config file does not exist in the default path. Add the following 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.gz
Decompress the sample project.
tar zxf aliyun-oss-c-sdk-demo.tar.gz
NoteWhen you install oss-c-sdk-demo-specified-installation, you must specify the installation directory: **/home/your/oss/csdk**. You do not need to specify installation directories for other sample projects because other sample projects are automatically installed based on OSS SDK for C and other dependent third-party libraries. For more information about the Linux sample project, see Use Alibaba Cloud OSS SDK for C in Linux.
Compile the sample project.
Go to the project directory (oss-c-sdk-demo-xxx).
Run the
make
command to compile the sample project.NoteReplace OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, and BUCKET_NAME in the sample project with valid values. If OSS SDK for C and the dynamic libraries of the dependent libraries are not in the system directory, use
LD_LIBRARY_PATH
to specify the directory of OSS SDK for C and the dynamic libraries of the dependent libraries.Run the
./main
command to run executable programs.To recompile the sample project, run the
make clean
command.
Install OSS SDK for C on Windows
Download and install OSS SDK for C.
Download and decompress the package of the sample project.
Use Visual Studio to compile the sample project.
If you use Visual Studio 2012 or later, you are prompted to choose whether to upgrade the project version to adapt to the latest versions of the compiler and libraries. We recommend that you use versions that match your project. If the project uses the compiler and libraries of the latest versions, upgrade the project. Otherwise, you do not need to upgrade the project.
When you compile the sample project, replace the following parameters in oss_config.c with valid values: OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, BUCKET_NAME, OBJECT_NAME, MULTIPART_UPLOAD_FILE_PATH, and DIR_NAME.
For more information about how to use Visual Studio to run the sample project, see Use Alibaba Cloud OSS SDK for C in Windows.