This document describes the compilation methods and compilation configuration options of the SDK for C, as well as the compilation environment setup and compilation samples in the Linux and Windows development environments.
SDK for C Compilation Method Description
The SDK for C supports the following compilation methods.
CMake Method
We recommend you use CMake, a cross-platform compilation tool, for compilation in the Linux and Windows development environments.
The CMake method uses CMakeLists.txt as the compilation configuration options input file.
Makefile
For environments that don't support CMake, Makefile can be used for compilation.
The Makefile method is consistent with SDK version 3.0.3 and earlier versions. It uses make.settings as the compilation configuration options input file. After making modifications, simply execute 'make'.
Code Extraction Method
This method allows you to select features based on your needs and extract the relevant code into a separate folder. The code hierarchy in the folder is concise, making it easy for you to copy and integrate it into your own development environment.
This method relies on the cmake tool. Configure the relevant feature module switches in the CMakeLists.txt file and set EXTRACT_SRC to ON. Then run the following command in a Linux environment:
mkdir buildcd buildcmake ..
You can find the related code files in the output/qcloud_iot_c_sdk directory. The directory structure is as follows:
qcloud_iot_c_sdk├── include│ ├── config.h│ ├── exports├── platform└── sdk_src└── internal_inc
The include directory contains the API and variable parameters provided by the SDK for the user. The file config.h contains the compilation macros generated based on the compilation options.
The platform directory contains platform-related code, which can be modified and adapted according to the specific conditions of the device.
The sdk_src directory contains the core logic and protocol-related code of the SDK, which generally does not require modification. The internal_inc directory contains header files used internally by the SDK.
Note:
Users can copy qcloud_iot_c_sdk to their target platform's compilation development environment and modify the compilation options according to the specific situation.
SDK for C Compilation Option Description
Compilation configuration options
Most of the following configuration options apply to both cmake and make. The ON value in setting.cmake corresponds to y in make.setting, and OFF corresponds to n.
Name | CMake Value | Description |
BUILD_TYPE | release/debug | release: Do not enable IOT_DEBUG information, compile and output to the release directory. debug: Enable IOT_DEBUG information, compile and output to the debug directory. |
EXTRACT_SRC | ON/OFF | Whether to enable code extraction, which takes effect only for CMake. |
COMPILE_TOOLS | gcc | Supports gcc and msvc, cross-compilers can also be used. For example, arm-none-linux-gnueabi-gcc. |
PLATFORM | Linux | Includes Linux/Windows/FreeRTOS/nonOS. |
FEATURE_MQTT_COMM_ENABLED | ON/OFF | Whether to enable MQTT channel. |
FEATURE_MQTT_DEVICE_SHADOW | ON/OFF | Whether to enable device shadow. |
FEATURE_COAP_COMM_ENABLED | ON/OFF | Whether to enable CoAP channel. |
FEATURE_GATEWAY_ENABLED | ON/OFF | Whether to enable gateway feature. |
FEATURE_OTA_COMM_ENABLED | ON/OFF | Whether to enable OTA firmware update. |
FEATURE_OTA_SIGNAL_CHANNEL | MQTT/COAP | OTA signaling channel type. |
FEATURE_AUTH_MODE | KEY/CERT | Access Authentication Method. |
FEATURE_AUTH_WITH_NOTLS | ON/OFF | OFF: TLS enabled. ON: TLS disabled. |
FEATURE_DEV_DYN_REG_ENABLED | ON/OFF | Whether to enable dynamic device registration. |
FEATURE_LOG_UPLOAD_ENABLED | ON/OFF | Log Reporting Switch. |
FEATURE_EVENT_POST_ENABLED | ON/OFF | Event Reporting Switch. |
FEATURE_DEBUG_DEV_INFO_USED | ON/OFF | Whether to enable device information source acquisition. |
FEATURE_SYSTEM_COMM_ENABLED | ON/OFF | Backend Time Acquisition Switch. |
FEATURE_AT_TCP_ENABLED | ON/OFF | Whether to enable TCP feature in AT module. |
FEATURE_AT_UART_RECV_IRQ | ON/OFF | Whether to enable receipt interruption feature in AT module. |
FEATURE_AT_OS_USED | ON/OFF | Whether to enable multithreaded feature in AT module. |
FEATURE_AT_DEBUG | ON/OFF | Whether to enable debugging feature in AT module. |
FEATURE_MULTITHREAD_TEST_ENABLED | ON/OFF | Whether to compile the Linux multithreaded test routine. |
There is a dependency relationship between the configuration options. A configuration option is valid only when the value of its dependent option is valid as shown below:
Name | Dependent option | Effective value |
FEATURE_MQTT_DEVICE_SHADOW | FEATURE_MQTT_COMM_ENABLED | ON |
FEATURE_GATEWAY_ENABLED | FEATURE_MQTT_COMM_ENABLED | ON |
FEATURE_OTA_SIGNAL_CHANNEL(MQTT) | FEATURE_OTA_COMM_ENABLED FEATURE_MQTT_COMM_ENABLED | ON ON |
FEATURE_OTA_SIGNAL_CHANNEL(COAP) | FEATURE_OTA_COMM_ENABLED FEATURE_COAP_COMM_ENABLED | ON ON |
FEATURE_AUTH_WITH_NOTLS | FEATURE_AUTH_MODE | KEY |
FEATURE_AT_UART_RECV_IRQ | FEATURE_AT_TCP_ENABLED | ON |
FEATURE_AT_OS_USED | FEATURE_AT_TCP_ENABLED | ON |
FEATURE_AT_DEBUG | FEATURE_AT_TCP_ENABLED | ON |
Device information options
After creating a device in the Tencent Cloud IoT Console, you need to configure the device information (ProductID/DeviceName/DeviceSecret/Cert/Key file) in the SDK to ensure proper operation. In the development phase, the SDK provides two methods of storing device information:
Stored in code (compilation option DEBUG_DEV_INFO_USED = ON), then modify the device information in
platform/os/xxx/HAL_Device_xxx.c. This method can be used on platforms without a file system.Stored in configuration files (compilation option DEBUG_DEV_INFO_USED = OFF), then modify the device information in the
device_info.json file. This method does not require recompiling the SDK to change the device information and is recommended for development on Linux/Windows platforms.