Integrate the SDK
Update time: 2023/03/23 16:41:42
From NIM SKD v8.4.0, the directory of the SDK is adjusted. Cmake manages the C++ wrapper layer. Depending on the situation, appropriate modifications may be required when accessing the C++ encapsulation layer.
├─bin ├─include ├─lib └─wrapper
libstores the dynamic library files of the NIM SDK in the C language. Package the required modules when you release your app. Files with the
libextension are the symbolic link file of the dynamic library in Windows.
(lib)nim(.dll|.so|.dylib): instant messaging
(lib)nim_chatroom(.dll|.so|.dylib): chat room
(lib)h_available(.dll|.so|.dylib): Highly-availability module, dependent by the previous three modules
(lib)nim_tools_http(.dll|.so|.dylib): HTTP utility library
nim_audio.dll: audio decoding library that only supports Windows
nrtc.dll: audio and video call library that only supports Windows
node-nim.node: NIM SDK Node encapsulation layer, used for access in the Electron and Node.js environments.
- Other (system) dependencies, such as
includedirectory stores the header files of the NIM C SDK.
wrapperdirectory stores the source code of the C++ wrapper layer (including header files).
If you want to integrate the NIM SDK with a pure C interface, you can complete the following steps.
- Add the
includefolder in the search path of header files.
- Add the lib directory as the search path for dependency libraries.
- Add the static library file under the lib directory as an additional dependency library of your existing project.
Integrate the SDK using CMake
If your original project is managed based on CMake, you can complete the following steps.
wrapperdirectory as a subdirectory using the
INCLUDE_DIRECTORIESmethod to add the
wrapperfolders as search paths of header files.
TARGET_LINK_LIBRARIESto add link libraries as needed. Libraries:
nim_cpp_wrapper: NIM C++ library wrapper.
nim_chatroom_cpp_wrapper: Chatroom C++ library wrapper.
nim_wrapper_util: The utility library of NIM and Chatroom C++ library wrapper.
nim_tools_cpp_wrapper: the C++ library wrapper of NIM HTTP component.
nim_qchat_cpp_wrapper: the C++ library wrapper of NIM QChat.
Conventional methods (Visual Studio, Qt, and Xcode)
To access the C++ wrapper layer using the conventional method, you must generate the binary file of the C++ wrapper layer. Based on the runtime library and platform tool set of your project, generate the binary file of the wrapper layer. The following configurations are provided for your to generate the C++ wrapper layer in different situations. You only need to select one of the options that suit your project configuration.
Use CMake GUI
Use the CMake GUI tool to open the C++ wrapper layer folder and configure the generated cache directory.
After clicking the Configure button, you will be prompted to configure the project. You can see the figure below to configure your project.
Clicking the Finish button to initialize the project.
Configure the option to generate the project file on the interface, and then click the Generate button to generate the project file.
See the following configuration:
You can choose whether to generate a dynamic library or a static library by configuring
BUILD_SHARED_LIBS. By default, a static library is generated. The
CMAKE_INSTALL_PREFIXoption determines the export directory of the C++ header files and library files, which can be specified as the root directory of the SDK.
Click the Open Project button to open the project.
INSTALLin the opened project.
After the generation is complete, the header files and library files of the C++ wrapper layer will be automatically copied to the
libdirectories under the root directory of the SDK.
Install configuration: "Debug" Installing: E:/nim-sdk/lib/nim_wrapper_util_d.lib Installing: E:/nim-sdk/lib/nim_cpp_wrapper_d.lib Installing: E:/nim-sdk/lib/nim_chatroom_cpp_wrapper_d.lib Installing: E:/nim-sdk/lib/nim_tools_cpp_wrapper_d.lib Installing: E:/nim-sdk/include/nim_chatroom_cpp_wrapper Installing: E:/nim-sdk/include/nim_chatroom_cpp_wrapper/api Installing: E:/nim-sdk/include/nim_chatroom_cpp_wrapper/api/nim_chatroom_cpp.h ....... Installing: E:/nim-sdk/include/nim_cpp_wrapper Installing: E:/nim-sdk/include/nim_cpp_wrapper/api .......
In the project, add the
includedirectory as the search path of header files, add the
libdirectory to the search path of library files of your project, and link the specified library file.
Take Visual Studio as an example:
- Search path of header files, right click Properties -> C/C++ -> General, "AdditionalInclude Directories".
- Search path of library files, right click Properties -> Linker -> General, "AdditionalLibrary Directories"
- Link the library file. right click Properties -> Linker -> Input -> Additional LibraryDirectories.
If you upgrade from the SDK earlier than v8.4.0 to SDK v8.4.0, you must change theinclude path of the original header file from the original
nim_sdk to the
Use the command line tool
In most cases, you must automate the compilation step in the CI integration phase, you can use the command line to generate the C++ wrapper layer code:
# Create a new build folder in the SDK directory to cache the temporary files generated when compiling the C++ wrapper layer md build && cd build # Generate a project file, you can specify different parameters to determine the properties of the generated project file # Add -DCMAKE_CXX_FLAGS_DEBUG=/MTd -DCMAKE_CXX_FLAGS_RELEASE=/MT to generate a MTd/MT project # Add -DBUILD_SHARED_LIBS=ON to generate a dynamic library project # Add -G"Visual Studio 15 2017 Win64" to generate a VS2017 64-bit project # Add -G"Visual Studio 14 2015" to generate a VS2015 project # Add -T"v141_xp" to generate projects that support Windows XP cmake ../wrapper # Compile project files and export header files and library files # The --build parameter describes the project to be compiled in the current directory # The --config parameter specifies whether you want to compile the Release or Debug version of the library file # The --target indicates the specified target you want to compile, use install here. Pay attention to the casing of `install` under macOS cmake --build . --config Debug --target install
Teamwork and CI integration
DO NOT directly reference the project files generated by CMake into the project, because CMake uses the absolute path to write into the project configuration file (
.vcxproj). The project files you generate on your own device cannot be used on other computers.
Use a custom script to always execute CMake before compilation to generate and compile the project to obtain the required binary during Continuous integration (CI) or when collaborating with other teammates.
You can also upload the generated
.lib to your code version control system. Although this is convenient, uploading binary files to the version control system every time the SDK is updated will increase the size of the repository.
If your project is already managed based on CMake, you only need to use the
wrapper as a dependency of your project, and no additional configuration is required.
- C implementation
- C implementation
- Integrate the SDK using CMake
- Conventional methods (Visual Studio, Qt, and Xcode)
- Teamwork and CI integration