Building a Plugin

Configuring CMakeLists.txt

The CMakeLists.txt file is used to set the plugin name, add the target file for generating the plugin dynamic library, and link the related third-party library. Each plugin corresponds to a CMakeLists.txt file. For the CMakeLists.txt file of the new plugin, you only need to modify the name of the generated plugin and the target file of the generated plugin, and use other configuration items of the original plugin. The following uses the mxpi_sampleplugin plugin as an example. (For details about the CMakeLists.txt file, see Sample Plugin CMakeLists (CMakeLists.txt).)

set(PLUGIN_NAME "mxpi_sampleplugin")
set(TARGET_LIBRARY ${PLUGIN_NAME})

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations)
add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}")
add_definitions(-DENABLE_DVPP_INTERFACE)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(${TARGET_LIBRARY} SHARED MxpiSamplePlugin.cpp)

target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstbase-1.0 gmodule-2.0)
target_link_libraries(${TARGET_LIBRARY} mxpidatatype plugintoolkit mxbase mindxsdk_protobuf)

In the preceding information, mxpi_sampleplugin and MxpiSamplePlugin.cpp indicate the name and object file of the generated plugin, respectively. Other configuration items are the same as those of the original plugin.

The Atlas 500 AI edge station can only be used as the operating environment. The EulerOS, driver, and firmware are preinstalled before delivery. If no ARM-based device is available, you can cross-compile SDK applications on Ubuntu 18.04 x86_64, and then deploy the compiled applications on the Atlas 500 AI edge station. For details, see Cross Compilation Plugin Example.

CLI Compilation

The CLI compilation is used to compile and generate the plugin based on the configuration of the CMakeLists.txt file.

  1. Create a MxpiSamplePlugin directory.
    cd {sdk_install_path}/samples/
    mkdir MxpiSamplePlugin

    {sdk_install_path} indicates the installation path of the MindX SDK.

  2. Go to the MxpiSamplePlugin directory.
    cd MxpiSamplePlugin
  3. Save the plugin header file, source file, and CMakeLists.txt file to the MxpiSamplePlugin directory.
  4. Create a build folder and go to the build folder.
    mkdir build
    cd build
  5. Create a Makefile file to avoid contaminating the CMakeLists.txt file of the project.
    cmake ..
  6. Build the project based on the generated Makefile file.
    make -j
  7. Set the permission on the .so file of the generated plugin to 640 and copy the file to the plugins directory.
    chmod 640 libmxpi_sampleplugin.so
    cp libmxpi_sampleplugin.so ../../../lib/plugins/