diff --git a/include/Nazara/Core/DynLib.hpp b/include/Nazara/Core/DynLib.hpp index 8e6f6d1d0..0f51eaaaa 100644 --- a/include/Nazara/Core/DynLib.hpp +++ b/include/Nazara/Core/DynLib.hpp @@ -16,7 +16,7 @@ #elif defined(NAZARA_PLATFORM_LINUX) #define NAZARA_DYNLIB_EXTENSION ".so" #elif defined(NAZARA_PLATFORM_MACOS) - #define NAZARA_DYNLIB_EXTENSION ".dynlib" + #define NAZARA_DYNLIB_EXTENSION ".dylib" #else #error OS not handled #endif @@ -40,7 +40,7 @@ namespace Nz bool IsLoaded() const; - bool Load(const std::filesystem::path& libraryPath); + bool Load(std::filesystem::path libraryPath); void Unload(); DynLib& operator=(const DynLib&) = delete; diff --git a/src/Nazara/Core/DynLib.cpp b/src/Nazara/Core/DynLib.cpp index 90de8ae26..e7658b314 100644 --- a/src/Nazara/Core/DynLib.cpp +++ b/src/Nazara/Core/DynLib.cpp @@ -74,10 +74,13 @@ namespace Nz * * \remark Produces a NazaraError if library is could not be loaded */ - bool DynLib::Load(const std::filesystem::path& libraryPath) + bool DynLib::Load(std::filesystem::path libraryPath) { Unload(); + if (libraryPath.extension() != NAZARA_DYNLIB_EXTENSION) + libraryPath += NAZARA_DYNLIB_EXTENSION; + auto impl = std::make_unique(this); if (!impl->Load(libraryPath, &m_lastError)) { diff --git a/src/Nazara/Core/Posix/DynLibImpl.cpp b/src/Nazara/Core/Posix/DynLibImpl.cpp index 27eb38df6..22dd3e851 100644 --- a/src/Nazara/Core/Posix/DynLibImpl.cpp +++ b/src/Nazara/Core/Posix/DynLibImpl.cpp @@ -45,12 +45,8 @@ namespace Nz bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) { - std::filesystem::path path = libraryPath; - if (path.extension() != ".so") - path += ".so"; - dlerror(); // Clear error flag - m_handle = dlopen(path.generic_u8string().data(), RTLD_LAZY | RTLD_GLOBAL); + m_handle = dlopen(libraryPath.generic_u8string().data(), RTLD_LAZY | RTLD_GLOBAL); if (m_handle) return true; diff --git a/src/Nazara/Core/Win32/DynLibImpl.cpp b/src/Nazara/Core/Win32/DynLibImpl.cpp index 443b5fb18..76bafacd3 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.cpp +++ b/src/Nazara/Core/Win32/DynLibImpl.cpp @@ -33,11 +33,7 @@ namespace Nz bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) { - std::filesystem::path path = libraryPath; - if (path.extension() != ".dll") - path += ".dll"; - - m_handle = LoadLibraryExW(ToWideString(path.generic_u8string()).data(), nullptr, (path.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); + m_handle = LoadLibraryExW(ToWideString(libraryPath.generic_u8string()).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); if (m_handle) return true; else