Deployment with thirdparty libraries
PlannedI want to deploy our own Nx Plugin using curl and opencv as self contained library, for Windows OS.
How to keep these links even if working on different PC?
Currently, build has been done successfully locally, and loaded also successfully.
However when I copied that build output to different PC and placed to plugin folder,
failed loading plugin.
Same issue as this post, but this seems for Linux:
What I have done is as follows:
1. Copied curl and opencv folders to different PC.
2. Added the file paths needed to the system environment variable "Path."
However not changed.
This is the log:
2025-03-13 18:07:35.349 27a8 INFO PluginManager(0x1d546ac9f00): Considering to load Server plugin [C:/Program Files/Network Optix/Nx Witness/MediaServer/plugins/my_integration_plugin/my_integration_plugin.dll]
2025-03-13 18:07:35.350 27a8 ERROR PluginManager(0x1d546ac9f00): Failed loading Server Plugin [C:/Program Files/Network Optix/Nx Witness/MediaServer/plugins/my_integration_plugin/my_integration_plugin.dll] (): [cannotLoadLibrary]: Cannot load library C:\Program Files\Network Optix\Nx Witness\MediaServer\plugins\trimmy_integration_plugin\my_integration_plugin.dll: 指定されたモジュールが見つかりません。
In case, I attach cmake file content totally.
Thanks,
cmake_minimum_required(VERSION 3.14)
project(trimmy_integration_plugin)set(metadataSdkDir "" CACHE PATH "Path to unpacked VMS Metadata SDK zip.")
if(metadataSdkDir STREQUAL "")
set(metadataSdkDir ${CMAKE_CURRENT_LIST_DIR}/../..) #< Assume building samples inside the SDK.
if(NOT EXISTS ${metadataSdkDir}/src/nx/sdk OR NOT EXISTS ${metadataSdkDir}/nx_kit/src/nx/kit)
message(FATAL_ERROR "Define metadataSdkDir cache variable to point to the unzipped SDK.")
endif()
endif()set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)if(UNIX)
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--disable-new-dtags")
endif()
set(CMAKE_SKIP_BUILD_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_INSTALL_RPATH "$ORIGIN")if(MSVC)
add_compile_options("/utf-8")
string(APPEND CMAKE_CXX_FLAGS " /MP")
add_compile_options("/wd4819")
add_compile_options("/wd4996")
add_compile_options("/wd4101")
add_compile_options("/wd4228")
add_compile_options("/wd4244")
add_compile_options("/wd4267")
add_compile_options("/wd4305")
add_compile_options("/Z7")
endif()if(WIN32)
set(API_IMPORT_MACRO "__declspec(dllimport)")
set(API_EXPORT_MACRO "__declspec(dllexport)")
else()
set(API_IMPORT_MACRO "")
set(API_EXPORT_MACRO "__attribute__((visibility(\"default\")))")
endif()#--------------------------------------------------------------------------------------------------
set(nxKitLibraryType "STATIC" CACHE STRING "" FORCE)
set(nxKitWithTests "NO" CACHE STRING "" FORCE)add_subdirectory(${metadataSdkDir}/nx_kit ${CMAKE_CURRENT_BINARY_DIR}/nx_kit)
#--------------------------------------------------------------------------------------------------
set(SDK_SRC_DIR ${metadataSdkDir}/src)
file(GLOB_RECURSE SDK_SRC CONFIGURE_DEPENDS ${SDK_SRC_DIR}/*)add_library(nx_sdk STATIC ${SDK_SRC})
target_include_directories(nx_sdk PUBLIC ${SDK_SRC_DIR})
target_link_libraries(nx_sdk PRIVATE nx_kit)target_compile_definitions(nx_sdk PRIVATE NX_PLUGIN_API=${API_EXPORT_MACRO})
#--------------------------------------------------------------------------------------------------
set(TRIMMY_INTEGRATION_PLUGIN_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
file(GLOB_RECURSE TRIMMY_INTEGRATION_PLUGIN_SRC CONFIGURE_DEPENDS ${TRIMMY_INTEGRATION_PLUGIN_SRC_DIR}/*)find_package(OpenCV REQUIRED)
# Static cURL Linking
set(CURL_LIBRARY "C://curl//lib//libcurl.lib") # Path to the static library
set(CURL_INCLUDE_DIR "C://curl//include") # Path to the include directory
add_definitions(-DCURL_STATICLIB) # Define CURL_STATICLIB to use static libraryadd_library(trimmy_integration_plugin SHARED ${TRIMMY_INTEGRATION_PLUGIN_SRC})
include_directories(trimmy_integration_plugin ${ADDITIONAL_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS})
target_include_directories(trimmy_integration_plugin PRIVATE ${TRIMMY_INTEGRATION_PLUGIN_SRC_DIR} ${CURL_INCLUDE_DIR})
target_link_libraries(trimmy_integration_plugin PRIVATE ${OpenCV_LIBRARIES})
target_link_libraries(trimmy_integration_plugin PRIVATE nx_kit nx_sdk)# Static link cURL
target_link_libraries(trimmy_integration_plugin PRIVATE ${CURL_LIBRARY})target_compile_definitions(trimmy_integration_plugin
PRIVATE NX_PLUGIN_API=${API_EXPORT_MACRO}
)if(NOT WIN32)
target_link_libraries(trimmy_integration_plugin PRIVATE pthread)
endif()
-
Hello,
By the linkt to the post you reffer there is a kay phrase
Instead, the separate directory should be created with the same name a plugin has,
In the log snippet you've shared, I see
Server Plugin [C:/Program Files/Network Optix/Nx Witness/MediaServer/plugins/my_integration_plugin/my_integration_plugin.dll] (): [cannotLoadLibrary]: Cannot load library C:\Program Files\Network Optix\Nx Witness\MediaServer\plugins\trimmy_integration_plugin\my_integration_plugin.dll: 指定されたモジュールが見つかりません。
In the first occurrence, the folder name is “my_integration_plugin”. In the second, it's "trimmy_integration_plugin".
In the cmake file you've shared, the binary name is supposed to be "trimmy_integration_plugin"
add_library(trimmy_integration_plugin SHARED ${TRIMMY_INTEGRATION_PLUGIN_SRC})
That implies the folder name is to be “trimmy_integration_plugin”, thus the full path would comprise "C:/Program Files/Network Optix/Nx Witness/MediaServer/plugins/trimmy_integration_plugin/trimmy_integration_plugin.dll
Please, check your naming.
0 -
Thank you for reply.
I changed folder name for security, so that's not problem.
As you mentioned, actually output dll's name is trimmy_integration.dll.
Apart from this, I want to know how to keep links to 3rd party libraries also while copying to other Windows environment.
0 -
Hi,
> I changed folder name for security, so that's not problem.
I'm afraid, I have no idea what this means, but please keep in mind
If the folder name does not comply with the rules described above the plugin binary won't be loaded.Here is the article that would help you to choose the proper solution meeting your requirements.
https://support.networkoptix.com/hc/en-us/articles/360058885733-Loading-Plugins
Please, refer to the Linked DLL lookup on Windows section, since you're using Windows.
If the Plugin DLL resides in a directory with other Plugins — i.e. without a defined home directory (see above) — Nx Witness Server instructs Windows to look for DLLs which may be required for the Plugin’s DLL by using "default DLL search order" (defined by Windows), but excluding the current directory of the process.
If the Plugin DLL resides in a dedicated directory (its home directory) with other DLLs that it uses, Nx Witness Server instructs Windows to look for those DLLs in the Plugin’s home directory instead of using "default DLL search order" (defined by Windows).
More details on the default DLL search order can be found here.
https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order
So, as far as I understood, in your case, in the current configuration the solution would be copying all the dependency binary files (with no subfolders) to the plugin's home directory, i.e. C:/Program Files/Network Optix/Nx Witness/MediaServer/plugins/trimmy_integration_plugin
0
Please sign in to leave a comment.
Comments
3 comments