From f01fedf9d5c4505909682109aca9bc903c8c5e56 Mon Sep 17 00:00:00 2001 From: seanyen Date: Mon, 24 Feb 2020 16:37:04 -0800 Subject: [PATCH 1/2] rework `lib` strip for Windows. --- .../include/pluginlib/class_loader_imp.hpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index d45b5914..315d3ef2 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -357,12 +357,30 @@ std::vector ClassLoader::getAllLibraryPathsToTry( std::string stripped_library_name = stripAllButFileFromPath(library_name); std::string stripped_library_name_with_extension = stripped_library_name + non_debug_suffix; +#ifdef _WIN32 + // try to strip the leading `lib` from the library path. + // Windows doesn't have the `lib` prefix convention for shared libraries. + const std::string lib_suffix = "lib"; + std::string stripped_library_name_win32 = stripped_library_name; + std::string stripped_library_name_with_extension_win32 = stripped_library_name + non_debug_suffix; + if (boost::starts_with(stripped_library_name, lib_suffix)) + { + stripped_library_name_win32 = stripped_library_name_win32.substr(lib_suffix.length()); + stripped_library_name_with_extension_win32 = stripped_library_name_with_extension_win32.substr(lib_suffix.length()); + } + ROS_INFO_STREAM("stripped_library_name_win32: " << stripped_library_name_win32); + ROS_INFO_STREAM("stripped_library_name_with_extension_win32: " << stripped_library_name_with_extension_win32); +#endif + const std::string path_separator = getPathSeparator(); for (unsigned int c = 0; c < all_paths_without_extension.size(); c++) { std::string current_path = all_paths_without_extension.at(c); all_paths.push_back(current_path + path_separator + library_name_with_extension); all_paths.push_back(current_path + path_separator + stripped_library_name_with_extension); +#ifdef _WIN32 + all_paths.push_back(current_path + path_separator + stripped_library_name_with_extension_win32); +#endif // We're in debug mode, try debug libraries as well if (debug_library_suffix) { all_paths.push_back( @@ -370,6 +388,11 @@ std::vector ClassLoader::getAllLibraryPathsToTry( all_paths.push_back( current_path + path_separator + stripped_library_name + class_loader::systemLibrarySuffix()); +#ifdef _WIN32 + all_paths.push_back( + current_path + path_separator + stripped_library_name_win32 + + class_loader::systemLibrarySuffix()); +#endif } } @@ -805,7 +828,7 @@ std::string ClassLoader::stripAllButFileFromPath(const std::string & path) if (std::string::npos == c) { return path; } else { - return path.substr(c, path.size()); + return path.substr(c + 1); } } From 5f38258de1e492be40ab05f0433c6136b03db9e5 Mon Sep 17 00:00:00 2001 From: seanyen Date: Tue, 25 Feb 2020 12:15:13 -0800 Subject: [PATCH 2/2] remove extra logging. --- pluginlib/include/pluginlib/class_loader_imp.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index 315d3ef2..49600a46 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -368,8 +368,6 @@ std::vector ClassLoader::getAllLibraryPathsToTry( stripped_library_name_win32 = stripped_library_name_win32.substr(lib_suffix.length()); stripped_library_name_with_extension_win32 = stripped_library_name_with_extension_win32.substr(lib_suffix.length()); } - ROS_INFO_STREAM("stripped_library_name_win32: " << stripped_library_name_win32); - ROS_INFO_STREAM("stripped_library_name_with_extension_win32: " << stripped_library_name_with_extension_win32); #endif const std::string path_separator = getPathSeparator();