Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] strip 'lib' prefix when loading library. #176

Open
wants to merge 2 commits into
base: melodic-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion pluginlib/include/pluginlib/class_loader_imp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,40 @@ std::vector<std::string> ClassLoader<T>::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());
}
#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(
current_path + path_separator + library_name + class_loader::systemLibrarySuffix());
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
}
}

Expand Down Expand Up @@ -805,7 +826,7 @@ std::string ClassLoader<T>::stripAllButFileFromPath(const std::string & path)
if (std::string::npos == c) {
return path;
} else {
return path.substr(c, path.size());
return path.substr(c + 1);
}
}

Expand Down