Skip to content

Commit

Permalink
Improved OS-specific handling of shared library name
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Jan 29, 2019
1 parent c8adc06 commit 954d04a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions deps/sharedlibpp/src/SharedLibraryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class shlibpp::SharedLibraryFactory::Private
bool isValid() const;
bool useFactoryFunction(void *factory);

static std::string platformSpecificLibName(const std::string& library);
void extendSearchPath(const std::string& path);
void readExtendedPathFromEnvironment();
std::string findLibraryInExtendedPath(const std::string& libraryName);
static std::vector<std::string> platformSpecificLibName(const std::string& library);

SharedLibrary lib;
SharedLibraryFactory::Status status;
Expand Down Expand Up @@ -84,22 +84,19 @@ shlibpp::SharedLibraryFactory::Private::Private(int32_t startCheck,
memset(&api, 0, sizeof(SharedLibraryClassApi));
}

std::string shlibpp::SharedLibraryFactory::Private::platformSpecificLibName(const std::string& library)
std::vector<std::string> shlibpp::SharedLibraryFactory::Private::platformSpecificLibName(const std::string& library)
{

#if defined(_WIN32)
#if _MSC_VER && !__INTEL_COMPILER
#if defined(NDEBUG)
return library + ".dll";
return {library + ".dll", library + "d.dll", "lib" + library + ".dll"};
#else
return library + "d.dll";
#endif
#else // Windows with other compilers
return "lib" + library + ".dll";
return {library + "d.dll", library + ".dll", "lib" + library + ".dll"};
#endif
#elif defined(__linux__)
return "lib" + library + ".so";
return {"lib" + library + ".so"};
#elif defined(__APPLE__)
return "lib" + library + ".dylib";
return {"lib" + library + ".dylib"};
#endif
}

Expand All @@ -111,10 +108,12 @@ std::string shlibpp::SharedLibraryFactory::Private::findLibraryInExtendedPath(co
}

for (const auto& path: extendedPath) {
std::string absolutePath = path + PATH_SEPARATOR + platformSpecificLibName(libraryName);
for (const auto& osLibName : platformSpecificLibName(libraryName)){
std::string absolutePath = path + PATH_SEPARATOR + osLibName;

if (std::ifstream(absolutePath)) {
return absolutePath;
if (std::ifstream(absolutePath)) {
return absolutePath;
}
}
}

Expand Down

0 comments on commit 954d04a

Please sign in to comment.