The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Compilation Environment (Linux and Windows)

Last updated: 2025-03-19 15:01:52

Linux (Ubuntu)

Note:
The Ubuntu version used for demonstration in this document is v16.04.
1. Installing necessary software The SDK requires CMake v3.5 or above. The CMake version installed by default is low. If compilation fails, please click download and refer to the Installation Instructions to download and install the specific version of CMake.
$ sudo apt-get install -y build-essential make git gcc cmake
2. Modifying Configuration Modify the CMakeLists.txt file in the root directory of the SDK and ensure the following options exist (using key authentication device as an example):
set(BUILD_TYPE "release")
set(COMPILE_TOOLS "gcc")
set(PLATFORM "linux")
set(FEATURE_MQTT_COMM_ENABLED ON)
set(FEATURE_AUTH_MODE "KEY")
set(FEATURE_AUTH_WITH_NOTLS OFF)
set(FEATURE_DEBUG_DEV_INFO_USED OFF)
3. Run the script for compilation
3.1 Below is a complete compilation library and demo:
./cmake_build.sh
3.2 The output library files, header files, and samples are in the output/release folder. After a complete compilation, if you only need to compile the demo, then run the following code:
./cmake_build.sh samples
4. Enter the device information Enter the device information created on the Tencent Cloud IoT platform (using key authentication device as an example) into the SDK root directory's device_info.json. Sample code is as follows:
"auth_mode":"KEY",
"productId":"S3EUVBQAZW",
"deviceName":"test_device",
"key_deviceinfo":{
"deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y"
}
5. Run Example The example output is located in the output/release/bin folder. For example, to run the data_template_sample example, enter ./output/release/bin/data_template_sample.

Windows Environment

Getting and installing Visual Studio 2019

1. Visit the Visual Studio download site, download and install Visual Studio 2019. The version downloaded and installed in this document is v16.2 Community.

2. Select "Desktop development with C++" and make sure "C++ CMAKE tools for Windows" is checked.


Compilation and running

1. Run Visual Studio, choose Open a local folder, and select the downloaded C SDK directory.

2. Fill in the device information of the device created in the Tencent Cloud IoT Communication Console (using a key-authenticated device as an example) into device_info.json. The sample code is as follows:
"auth_mode":"KEY",
"productId":"S3EUVBQAZW",
"deviceName":"test_device",
"key_deviceinfo":{
"deviceSecret":"vX6PQqazsGsMyf5SMfs6OA6y"
}
3. Double-click to open the CMakeLists.txt in the root directory and ensure the platform set in the compilation toolchain is Windows and the compiler is MSVC.

# Compilation toolchain
#set(COMPILE_TOOLS "gcc")
#set(PLATFORM "linux")
set(COMPILE_TOOLS "MSVC")
set(PLATFORM "windows")
4. Visual Studio will automatically build the CMake cache. Just wait for the build to complete.

5. After the cache build is complete, select Build > All Generation.

6. Choose the appropriate example to run, which should correspond to the user information.