From 5583b3e0f245c2f763abfba2d947884d33a14eaf Mon Sep 17 00:00:00 2001 From: QUYVN Date: Sun, 22 Mar 2026 04:42:26 +0000 Subject: [PATCH] fix load path so --- .../NavigationExample.csproj | 2 +- src/APIs/c_api/src/nav_c_api.cpp | 1 + .../include/robot/plugin_loader_helper.h | 2 +- .../robot_cpp/src/plugin_loader_helper.cpp | 29 +++++++++++-------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/examples/NavigationExample/NavigationExample.csproj b/examples/NavigationExample/NavigationExample.csproj index c98bcda..9ec6097 100644 --- a/examples/NavigationExample/NavigationExample.csproj +++ b/examples/NavigationExample/NavigationExample.csproj @@ -1,7 +1,7 @@ Exe - net6.0 + net10.0 true diff --git a/src/APIs/c_api/src/nav_c_api.cpp b/src/APIs/c_api/src/nav_c_api.cpp index 78a7f01..ab7ac21 100644 --- a/src/APIs/c_api/src/nav_c_api.cpp +++ b/src/APIs/c_api/src/nav_c_api.cpp @@ -83,6 +83,7 @@ extern "C" NavigationHandle navigation_create(void) // Using default constructor - initialization will be done via navigation_initialize() robot::PluginLoaderHelper loader; std::string path_file_so = loader.findLibraryPath("MoveBase"); + robot::log_warning("%s", path_file_so.c_str()); auto move_base_loader = boost::dll::import_alias( path_file_so, "MoveBase", boost::dll::load_mode::append_decorations); auto move_base_ptr = move_base_loader(); diff --git a/src/Libraries/robot_cpp/include/robot/plugin_loader_helper.h b/src/Libraries/robot_cpp/include/robot/plugin_loader_helper.h index 8a4458d..8660328 100644 --- a/src/Libraries/robot_cpp/include/robot/plugin_loader_helper.h +++ b/src/Libraries/robot_cpp/include/robot/plugin_loader_helper.h @@ -89,7 +89,7 @@ public: private: /** - * @brief Resolve library path (handle relative paths, search in search_paths) + * @brief Resolve library path (absolute, then PNKX_NAV_CORE_LIBRARY_PATH, search_paths_, cwd) * @param library_path Path from config (may be relative or absolute) * @return Resolved absolute path, or empty if not found */ diff --git a/src/Libraries/robot_cpp/src/plugin_loader_helper.cpp b/src/Libraries/robot_cpp/src/plugin_loader_helper.cpp index ea1dbe8..7049a61 100644 --- a/src/Libraries/robot_cpp/src/plugin_loader_helper.cpp +++ b/src/Libraries/robot_cpp/src/plugin_loader_helper.cpp @@ -98,7 +98,6 @@ std::string PluginLoaderHelper::findLibraryPath(const std::string& symbol_name) } } } - // Try LD_LIBRARY_PATH as fallback const char* ld_path = std::getenv("LD_LIBRARY_PATH"); if (ld_path) { @@ -199,21 +198,27 @@ std::string PluginLoaderHelper::resolveLibraryPath(const std::string& library_pa return ""; } - // If relative path, search in search_paths (build directory is already added) - std::string build_dir = getBuildDirectory(); - if (!build_dir.empty()) { - // First try in build directory - // Add .so extension if not present + // If relative path, search under PNKX_NAV_CORE_LIBRARY_PATH (':'-separated, like LD_LIBRARY_PATH) + const char* nav_lib_path_env = std::getenv("PNKX_NAV_CORE_LIBRARY_PATH"); + if (nav_lib_path_env) { std::string lib_path_with_ext = library_path; if (lib_path_with_ext.find(".so") == std::string::npos) { lib_path_with_ext += ".so"; } - std::filesystem::path full_path = std::filesystem::path(build_dir) / lib_path_with_ext; - if (std::filesystem::exists(full_path)) { - try { - return std::filesystem::canonical(full_path).string(); - } catch (...) { - return full_path.string(); + std::string nav_lib_paths(nav_lib_path_env); + std::stringstream ss(nav_lib_paths); + std::string base_dir; + while (std::getline(ss, base_dir, ':')) { + if (base_dir.empty()) { + continue; + } + std::filesystem::path full_path = std::filesystem::path(base_dir) / lib_path_with_ext; + if (std::filesystem::exists(full_path)) { + try { + return std::filesystem::canonical(full_path).string(); + } catch (...) { + return full_path.string(); + } } } }