From 925bdbaf7400c5e1a2d9fc4fb5a5791d832ac7ff Mon Sep 17 00:00:00 2001 From: Johnson Shih Date: Thu, 30 Aug 2018 11:54:19 -0700 Subject: [PATCH 1/8] Strip the 'lib' prefix when load library --- pluginlib/CMakeLists.txt | 5 +++ pluginlib/include/pluginlib/class_loader.hpp | 6 ++++ .../include/pluginlib/class_loader_imp.hpp | 36 ++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index 4d6f672d..99542532 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -16,6 +16,11 @@ if(CATKIN_ENABLE_TESTING) add_library(test_plugins EXCLUDE_FROM_ALL SHARED test/test_plugins.cpp) target_link_libraries(test_plugins ${class_loader_LIBRARIES}) + if(WIN32) + # On Windows, default library runtime output set to CATKIN_GLOBAL_BIN_DESTINATION, + # change it back to CATKIN_PACKAGE_LIB_DESTINATION to match the library path described in plugin description file + set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}) + endif() catkin_add_gtest(${PROJECT_NAME}_utest test/utest.cpp) if(TARGET ${PROJECT_NAME}_utest) diff --git a/pluginlib/include/pluginlib/class_loader.hpp b/pluginlib/include/pluginlib/class_loader.hpp index 7aaa0441..ab18b724 100644 --- a/pluginlib/include/pluginlib/class_loader.hpp +++ b/pluginlib/include/pluginlib/class_loader.hpp @@ -288,6 +288,12 @@ class ClassLoader : public ClassLoaderBase const std::string & library_name, const std::string & exporting_package_name); +#ifdef _WIN32 + std::string getClassLibraryPathFromLibraryName( + const std::string & library_name, + const std::string & package_name); +#endif + /// Return the paths where libraries are installed according to the Catkin build system. std::vector getCatkinLibraryPaths(); diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index f0a2c834..c75cb12e 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -413,8 +413,42 @@ std::string ClassLoader::getClassLibraryPath(const std::string & lookup_name) ROS_DEBUG_NAMED("pluginlib.ClassLoader", "Class %s maps to library %s in classes_available_.", lookup_name.c_str(), library_name.c_str()); + std::string library_path = getClassLibraryPathFromLibraryName(library_name, it->second.package_); + +#ifdef _WIN32 + // Windows does not add 'lib' prefix to libary name, remove the prefix and try again + if ("" == library_path) { + std::string only_path; + std::string only_file; + size_t c = library_name.find_last_of(getPathSeparator()); + if (std::string::npos == c) { + only_path = ""; + only_file = library_name; + } else { + only_path = library_name.substr(0, c + 1); + only_file = library_name.substr(c + 1, library_name.size()); + } + + const std::string lib_suffix = "lib"; + if (boost::starts_with(only_file, lib_suffix)) { + only_file = only_file.substr(lib_suffix.length()); + if (!only_file.empty()) { + const std::string new_library_name = only_path + only_file; + library_path = getClassLibraryPathFromLibraryName(new_library_name, it->second.package_); + } + } + } +#endif + + return library_path; +} + +template +std::string ClassLoader::getClassLibraryPathFromLibraryName(const std::string & library_name, const std::string & package_name) +/***************************************************************************/ +{ std::vector paths_to_try = - getAllLibraryPathsToTry(library_name, it->second.package_); + getAllLibraryPathsToTry(library_name, package_name); ROS_DEBUG_NAMED("pluginlib.ClassLoader", "Iterating through all possible paths where %s could be located...", From 8c7192135abf82b92aca2bdc8336e57fd8800b1a Mon Sep 17 00:00:00 2001 From: Johnson Shih Date: Fri, 14 Sep 2018 13:51:49 -0700 Subject: [PATCH 2/8] Set the test dll runtime output to CATKIN_PACKAGE_BIN_DESTINATION to match default --- pluginlib/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index 99542532..98e433a8 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -18,8 +18,8 @@ if(CATKIN_ENABLE_TESTING) target_link_libraries(test_plugins ${class_loader_LIBRARIES}) if(WIN32) # On Windows, default library runtime output set to CATKIN_GLOBAL_BIN_DESTINATION, - # change it back to CATKIN_PACKAGE_LIB_DESTINATION to match the library path described in plugin description file - set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}) + # change it back to CATKIN_PACKAGE_BIN_DESTINATION to match the library path described in plugin description file + set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}) endif() catkin_add_gtest(${PROJECT_NAME}_utest test/utest.cpp) From 064b9f513be0d7aab80956cd0a751ed4c7088b97 Mon Sep 17 00:00:00 2001 From: Johnson Shih Date: Fri, 14 Sep 2018 16:59:18 -0700 Subject: [PATCH 3/8] Set the Dll destination to CATKIN_PACKAGE_LIB_DESTINATION --- pluginlib/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index 98e433a8..99542532 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -18,8 +18,8 @@ if(CATKIN_ENABLE_TESTING) target_link_libraries(test_plugins ${class_loader_LIBRARIES}) if(WIN32) # On Windows, default library runtime output set to CATKIN_GLOBAL_BIN_DESTINATION, - # change it back to CATKIN_PACKAGE_BIN_DESTINATION to match the library path described in plugin description file - set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_BIN_DESTINATION}) + # change it back to CATKIN_PACKAGE_LIB_DESTINATION to match the library path described in plugin description file + set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}) endif() catkin_add_gtest(${PROJECT_NAME}_utest test/utest.cpp) From 9f9b9985c642dfcf1a930651821c223117069bc7 Mon Sep 17 00:00:00 2001 From: James Xu Date: Fri, 11 Jan 2019 11:44:55 -0800 Subject: [PATCH 4/8] fix getClassLibraryPathFromLibraryName definition (#4) --- pluginlib/include/pluginlib/class_loader.hpp | 2 -- pluginlib/include/pluginlib/class_loader_imp.hpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pluginlib/include/pluginlib/class_loader.hpp b/pluginlib/include/pluginlib/class_loader.hpp index ab18b724..1eac07bc 100644 --- a/pluginlib/include/pluginlib/class_loader.hpp +++ b/pluginlib/include/pluginlib/class_loader.hpp @@ -288,11 +288,9 @@ class ClassLoader : public ClassLoaderBase const std::string & library_name, const std::string & exporting_package_name); -#ifdef _WIN32 std::string getClassLibraryPathFromLibraryName( const std::string & library_name, const std::string & package_name); -#endif /// Return the paths where libraries are installed according to the Catkin build system. std::vector getCatkinLibraryPaths(); diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index c75cb12e..79836d5a 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -417,7 +417,7 @@ std::string ClassLoader::getClassLibraryPath(const std::string & lookup_name) #ifdef _WIN32 // Windows does not add 'lib' prefix to libary name, remove the prefix and try again - if ("" == library_path) { + if (library_path.empty()) { std::string only_path; std::string only_file; size_t c = library_name.find_last_of(getPathSeparator()); From e07bdd67d7d2170b2310326ea3eb1cb728d97773 Mon Sep 17 00:00:00 2001 From: James Xu Date: Fri, 11 Jan 2019 16:45:13 -0800 Subject: [PATCH 5/8] separate out RUNTIME_OUTPUT_DIRECTORY change (#5) --- pluginlib/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index 99542532..4d6f672d 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -16,11 +16,6 @@ if(CATKIN_ENABLE_TESTING) add_library(test_plugins EXCLUDE_FROM_ALL SHARED test/test_plugins.cpp) target_link_libraries(test_plugins ${class_loader_LIBRARIES}) - if(WIN32) - # On Windows, default library runtime output set to CATKIN_GLOBAL_BIN_DESTINATION, - # change it back to CATKIN_PACKAGE_LIB_DESTINATION to match the library path described in plugin description file - set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}) - endif() catkin_add_gtest(${PROJECT_NAME}_utest test/utest.cpp) if(TARGET ${PROJECT_NAME}_utest) From e38c28bbdb02b1479b75d3af772cf4bbd83412b6 Mon Sep 17 00:00:00 2001 From: James Xu Date: Fri, 11 Jan 2019 16:50:46 -0800 Subject: [PATCH 6/8] update RUNTIME_OUTPUT_DIRECTORY (#6) --- pluginlib/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pluginlib/CMakeLists.txt b/pluginlib/CMakeLists.txt index 4d6f672d..99542532 100644 --- a/pluginlib/CMakeLists.txt +++ b/pluginlib/CMakeLists.txt @@ -16,6 +16,11 @@ if(CATKIN_ENABLE_TESTING) add_library(test_plugins EXCLUDE_FROM_ALL SHARED test/test_plugins.cpp) target_link_libraries(test_plugins ${class_loader_LIBRARIES}) + if(WIN32) + # On Windows, default library runtime output set to CATKIN_GLOBAL_BIN_DESTINATION, + # change it back to CATKIN_PACKAGE_LIB_DESTINATION to match the library path described in plugin description file + set_target_properties(test_plugins PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_LIB_DESTINATION}) + endif() catkin_add_gtest(${PROJECT_NAME}_utest test/utest.cpp) if(TARGET ${PROJECT_NAME}_utest) From 0d452ea16794ed23dd59273e7c6c6d436eee2208 Mon Sep 17 00:00:00 2001 From: Lou Amadio Date: Tue, 29 Jan 2019 16:35:46 -0800 Subject: [PATCH 7/8] Add bin to path so devel\setup.bat works (#7) --- pluginlib/include/pluginlib/class_loader_imp.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index 8b275150..04ae281b 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -310,7 +310,12 @@ std::vector ClassLoader::getCatkinLibraryPaths() boost::split(catkin_prefix_paths, env_catkin_prefix_paths, boost::is_any_of(os_pathsep)); BOOST_FOREACH(std::string catkin_prefix_path, catkin_prefix_paths) { boost::filesystem::path path(catkin_prefix_path); - boost::filesystem::path lib("lib"); +#if WIN32 + boost::filesystem::path bin("bin"); + lib_paths.push_back((path / bin).string()); +#endif + + boost::filesystem::path lib("lib"); lib_paths.push_back((path / lib).string()); } } From 4de8d960674160b1586a97b7e49c43313f3a8993 Mon Sep 17 00:00:00 2001 From: James Xu Date: Tue, 5 Feb 2019 15:54:12 -0800 Subject: [PATCH 8/8] use spaces for tabs, use #ifdef instead of #if --- pluginlib/include/pluginlib/class_loader_imp.hpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index 04ae281b..5212caa4 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -310,12 +310,11 @@ std::vector ClassLoader::getCatkinLibraryPaths() boost::split(catkin_prefix_paths, env_catkin_prefix_paths, boost::is_any_of(os_pathsep)); BOOST_FOREACH(std::string catkin_prefix_path, catkin_prefix_paths) { boost::filesystem::path path(catkin_prefix_path); -#if WIN32 - boost::filesystem::path bin("bin"); - lib_paths.push_back((path / bin).string()); +#ifdef _WIN32 + boost::filesystem::path bin("bin"); + lib_paths.push_back((path / bin).string()); #endif - - boost::filesystem::path lib("lib"); + boost::filesystem::path lib("lib"); lib_paths.push_back((path / lib).string()); } }