Dave
Assistant Engineer
Assistant Engineer
  • UID627
  • Fans2
  • Follows0
  • Posts55
Reads:1208Replies:0

Compile and use Aliyun OSS C SDK in Windows

Created#
More Posted time:Sep 27, 2016 17:04 PM
Visual Studio (VS) is the first choice to compile and run C/C++ in Windows. The following table lists main VS versions released by Microsoft.

This document describes how to compile OSS C SDK and run sample programs with VS2008, VS2010, VS2012, VS2013, and VS2015 as examples.
Compile Aliyun OSS C SDK
VS2008
1. Open a project
Right-click oss_c_sdk_2008.sln, click Open With, and select Microsoft Visual Studio 2008.
If Microsoft Visual Studio 2008 is not available in the Open With dialog box, start Microsoft Visual Studio 2008, choose File > Open > Project/Solution, and select oss_c_sdk_2008.sln to open the project.
2. Set a startup project
Right-click oss_c_sdk_test and choose Set as StartUp Project.
3. Compile the SDK
Right-click oss_c_sdk_test in Solution Explorer and choose Rebuild. The compiled OSS C SDK library is stored in the project directory.
4. Possible problems
• Error:  error LNK2019: unresolved external symbol _oss_create_live_channel referenced in function _create_test_live_channel
Reason:  New files such as oss_live.c are not added to the project.
Solution:  Right-click oss_c_sdk, choose Add > Existing Item..., select all .h and .c files in the oss_c_sdk directory, and add them to the oss_c_sdk project.
• Error:  error LNK2019: unresolved external symbol impinet_addr@4 referenced in function _is_valid_ip
Reason:  oss_c_sdk_test lacks ws2_32.lib.
Solution:  Right-click oss_c_sdk_test, choose Properties > Configuration Properties > Linker > Input > Additional Dependencies and select ws2_32.lib.
• Error:  fatal error C1083: Cannot open include file: 'stdint.h': No such file or directory
Reason:  Lack of the header file stdint.h
Solution:  Change stdint.h.bak in third_party/include to stdint.h.
5. Library position
The compiled OSS C SDK library oss_c_sdk.lib is stored in Debug/Release under the project directory.
VS2010
1. Open a project
Right-click oss_c_sdk.sln, click Open With, and select Microsoft Visual Studio 2010.
2. Set a startup project
Right-click oss_c_sdk_test and choose Set as StartUp Project.
3. Compile the SDK
Right-click oss_c_sdk_test in Solution Explorer and choose Rebuild. The compiled OSS C SDK library is stored in the project directory.
4. Possible problems
• Error:  error MSB8008: Specified platform toolset (v140) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
Reason:  The PlatformToolset value is inconsistent with the current VS version.
Solution:  Choose Solution Explorer > oss_c_sdk > Properties > Configuration Properties > Platform Toolset and change V140 to V100.
5. Library position
The compiled OSS C SDK library oss_c_sdk.lib is stored in Debug/Release under the project directory.
VS2012
1. Open a project
Right-click oss_c_sdk.sln, click Open With, and select Microsoft Visual Studio 2012.
2. Set a startup project
Right-click oss_c_sdk_test and choose Set as StartUp Project.
3. Compile the SDK
Right-click oss_c_sdk_test in Solution Explorer and choose Rebuild. The compiled OSS C SDK library is stored in the project directory.
4. Possible problems
• Error:  error MSB8020: The builds tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install v140 to build using the v140 build tools.
Reason:  The PlatformToolset value is inconsistent with the current VS version.
Solution:  Choose Solution Explorer > oss_c_sdk > Properties > Configuration Properties > Platform Toolset and change V140 to Visual Studio 2012 (v110).
5. Library position
The compiled OSS C SDK library oss_c_sdk.lib is stored in Debug/Release under the project directory.
VS2013/VS2015
The procedures for compiling Aliyun OSS C SDK with VS2013 and VS2015 are the same. The following uses VS2015 as an example:
1. Open a project
Right-click oss_c_sdk.sln, click Open With, and select Microsoft Visual Studio 2015.
2. Set a startup project
Right-click oss_c_sdk_test and choose Set as StartUp Project.
3. Compile the SDK
Right-click oss_c_sdk_test in Solution Explorer and choose Rebuild. The compiled OSS C SDK library is stored in the project directory.
4. Library position
The compiled OSS C SDK library oss_c_sdk.lib is stored in Debug/Release under the project directory.
Run sample programs
Download
You can download the OSS C SDK sample program aliyun-oss-c-sdk-sample from:
• OSS official website
GitHub.
Run
VS2008, VS2010, VS2012, VS2013, and VS2015 samples are provided in the aliyun-oss-c-sdk-sample version.
• Replace oss_c_sdk.lib. The OSS C SDK package oss_c_sdk.lib is in oss-c-sdk-sample\oss-c-sdk\lib\Release.** This package is of the previous release.** You can continue to use the package or replace it with one that you compile.
• Open a project. Select a project based on your Visual Studio version. Right-click oss-c-sdk-sample.sln, click Open With, and select the corresponding Visual Studio to open the project.
• Modify parameters. Modify parameters OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET, and BUCKET_NAME in main.c based on the actual situation.
• Compile the OSS C SDK. Right-click oss-c-sdk-sample in Solution Explorer and choose Rebuild.
• Configure Environment. Choose Solution Explorer > oss-c-sdk-sample > Property > Configuration Properties > Debugging > Environment and change the configuration to PATH=..\oss-c-sdk\lib\Release\;%PATH%.
• Run the sample program. Press Ctrl + F5 to run the sample program.
How the sample project works
How is an OSS C SDK Sample project made? The procedures for making OSS C SDK sample projects by using VS2008, VS2010, VS2012, VS2013, and VS2015 are similar. The following describes how to use VS2012 to make an OSS C SDK sample project:
• Prepare library and header files, including SDK and third-party library and header files. Then, combine the SDK and third-party library and header files. The outcome is the oss-c-sdk-sample\oss-c-sdk directory, and the oss-c-sdk directory is under the project directory.
• Configure a header file path. Choose Solution Explorer > oss-c-sdk-sample > Property > Configuration Properties > VC++ Directories > Include Directories and add the following configuration:
..\oss-c-sdk\include
..\oss-c-sdk\include\apr
..\oss-c-sdk\include\aprutil
..\oss-c-sdk\include\curl
..\oss-c-sdk\include\mxml
..\oss-c-sdk\include\sdk
Configure a library path. Choose oss-c-sdk-sample > Property > Configuration Properties > Linker > General > Additional Library Directories and add ..\oss-c-sdk\lib\Release.
• Configure the library. Choose oss-c-sdk-sample > Property > Configuration Properties > Linker > Input > Additional Dependencies and add the following configuration:

libapr-1.lib
libaprutil-1.lib
curl.lib
mxml1.lib
oss_c_sdk.lib
ws2_32.lib
To write a program in an empty project or use OSS C SDK in an existing project, refer to the procedure for configuring a sample project.
Notes:
Currently, OSS C SDK supports Windows 32 (x86) rather than Windows x64. When using VS2015 to compile and run OSS C SDK, select Windows x86 instead of Windows x64.
Guest