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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
set(PLUGIN_NAME "mxpi_sampleplugin")
set(TARGET_LIBRARY ${PLUGIN_NAME})

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_compile_options(-std=c++14 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations)
add_link_options(-Wl,-z,relro,-z,now,-z,noexecstack -s -pie)
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.

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.
    1
    2
    cd {sdk_install_path}/samples/
    mkdir MxpiSamplePlugin
    

    {sdk_install_path} indicates the installation path of the Vision SDK package.

  2. Go to the MxpiSamplePlugin directory.
    1
    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.
    1
    2
    mkdir build
    cd build
    
  5. Create a Makefile file to avoid contaminating the CMakeLists.txt file of the project.
    1
    cmake ..
    
  6. Build the project based on the generated Makefile file.
    1
    make -j
    
  7. Set the permission on the .so file of the generated plugin to 440 and copy the file to the plugins directory.
    1
    2
    chmod 440 libmxpi_sampleplugin.so
    cp libmxpi_sampleplugin.so ../../../lib/plugins/