dylib

C++ cross-platform wrapper around dynamic loading of shared libraries (dll, so, dylib)

MIT License

Stars
266
dylib - 2.2.1 Latest Release

Published by martin-olivier about 1 year ago

Changelog

  • fix: CPack installation
dylib - 2.2.0

Published by martin-olivier about 1 year ago

Changelog

  • feat: MinGW support, requested by @lonnietc
  • feat: CPack support, requested by @KOLANICH
  • fix: WIN32_LEAN_AND_MEAN macro redefinition, thanks to @Aleksoid1978
  • fix: CMake improvements, thanks to @rmaxi-me
  • fix: workflows improvements
  • fix: cleaner documentation
dylib - 2.1.0

Published by martin-olivier over 2 years ago

Changelog

  • feat: std::filesystem::path support in dylib contructor
  • feat: dylib::add_filename_decorations and dylib::no_filename_decorations constants
  • feat: dylib::get_symbol public member function
  • feat: dylib::native_symbol_type public member type definition
  • feat: CI now checks both c++11 and c++17
  • fix: protected dylib members have been renamed
  • fix: timeout issues on windows CI
  • fix: cleaner documentation
dylib - 2.0.0

Published by martin-olivier over 2 years ago

Changelog

Dylib class is now RAII compliant

open(), close() and default constructor are not available anymore

Dylib constructor changes

// old API
dylib lib("./libs/libfoo", dylib::extension);

// new API
dylib lib("./libs", "foo");

The dylib class can now load a dynamic library from the system library path

// Load "foo" library from the system library path

dylib lib("foo");

The dylib class will now automatically add os decorations (os prefix and suffix) to the library name, but you can disable that by setting decorations parameter to false

// Windows -> "foo.dll"
// MacOS   -> "libfoo.dylib"
// Linux   -> "libfoo.so"

dylib lib("foo");

// Windows -> "foo.lib"
// MacOS   -> "foo.lib"
// Linux   -> "foo.lib"

dylib lib("foo.lib", false);

Changes on get_function return type

The return type of get_function is now a function pointer instead of an std::function

// old API
std::function<double(double, double)> adder = lib.get_function<double(double, double)>("adder");

// new API
double (*adder)(double, double) = lib.get_function<double(double, double)>("adder");

Changes on handle_error exception

handle_error exception is now called load_error

try {
    dylib lib("foo");
    lib.get_function<double(double, double)>("adder");
}

// old API
catch (const dylib::handle_error &e) {
    std::cout << e.what() << std::endl;
}

// new API
catch (const dylib::load_error &e) {
    std::cout << e.what() << std::endl;
}

DYLIB_API is not available anymore

To ensure the functions and variable of your future dynamic library will be exported on windows, you can use the following macro

#if defined(_WIN32) || defined(_WIN64)
#define LIB_EXPORT __declspec(dllexport)
#else
#define LIB_EXPORT
#endif

Or, you can add the following cmake rule that will export all symbols on windows

if(MSVC)
    set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()

Make sure to mark the functions and variables you want to export as extern "C" to avoid name mangling

The cmake rule that disable lib prefixes is now useless

Since dylib now handles libs prefix, you will need to remove the following cmake rule when building your dynamic libs

# remove the following rule from your cmakelists if you was using it with dylib 1.X.X
set_target_properties(target PROPERTIES PREFIX "")

Thanks

Huge thanks to @eyalroz for his help and contributions that made this update possible !

dylib - 1.8.3

Published by martin-olivier over 2 years ago

Changelog

  • fix: Improved CMake build system, thanks to @plevold
  • feat: Example about the usage of the library
  • feat: CI now checks the code using cpplint
  • fix: Cleaner documentation
dylib - 1.8.2

Published by martin-olivier over 2 years ago

Changelog

  • feat: native_handle function
  • feat: fetchContent example
  • fix: cleaner std::string overload for ctor and open
  • fix: cleaner documentation
dylib - 1.8.1

Published by martin-olivier over 2 years ago

Changelog

  • fix: crash when nullptr is passed as argument in get_function or get_variable when no dynamic lib is currently loaded
dylib - 1.8.0

Published by martin-olivier over 2 years ago

Changelog

  • feat: has_symbol function
  • feat: operator bool()
  • feat: Valgrind CI

Examples

has_symbol

void dylib_symbol_example(const dylib &lib)
{
    if (lib.has_symbol("GetModule"))
        std::cout << "GetModule has been found" << std::endl;
    else
        std::cout << "Could not found GetModule symbol" << std::endl;
}

operator bool()

void dylib_status_example(const dylib &lib)
{
    if (lib)
        std::cout << "something is curently loaded in the dylib object" << std::endl;
    if (!lib)
        std::cout << "nothing is curently loaded in the dylib object" << std::endl;
}
dylib - 1.7.1

Published by martin-olivier almost 3 years ago

Changelog:

  • Better error messages
  • Better documentation
  • Fixed CMakeLists.txt
dylib - 1.7.0

Published by martin-olivier almost 3 years ago

Changelog:

  • Added cross-platform DYLIB_API macro to be able to export symbols
  • The library is now in snake_case
  • Better documentation
  • Added win32 check on CMakeLists instead of a basic else
  • License is now up-to-date

Reviewers:

  • @MaximeHouis
  • @Breigner01
dylib - 1.6.2

Published by martin-olivier almost 3 years ago

Changelog:

  • Protect multiple inclusions by adding WIN32_LEAN_AND_MEAN flag for windows
  • Added documentation for DyLib class
  • Removed useless constexpr for default constructor of DyLib
dylib - 1.6.1

Published by martin-olivier about 3 years ago

Changelog:

  • Use of windows system error from GetLastError and FormatMessage
dylib - 1.6.0

Published by martin-olivier about 3 years ago

Changelog:

  • Function getVariable() now returns T & to be able to alter the value inside the dylib
  • Use of dlerror on unix and generic error on windows
  • Cleaner functions overloads
dylib - 1.5.1

Published by martin-olivier about 3 years ago

Changelog:

  • Errors are now in lowercase
  • Removed this before open and close functions
  • Inside close function, m_handle will be assigned to nullptr only if it wasn't already nullptr
dylib - 1.5.0

Published by martin-olivier over 3 years ago

Changelog:

  • Default constructor is now constexpr
  • Removed useless semicolons
  • Better documentation
dylib - 1.4.2

Published by martin-olivier over 3 years ago

Changelog:

  • Better documentation
  • Fix indentation
  • Fix warnings on unit tests
dylib - 1.4.1

Published by martin-olivier over 3 years ago

Changelog:

  • Fix std::move on DyLib::exception
  • Better documentation
dylib - 1.4

Published by martin-olivier over 3 years ago

Changelog:

  • Add && ctor and operator=(&&) overloads
  • Add ctor and open overloads
  • Add DyLib::extension
dylib - 1.3

Published by martin-olivier over 3 years ago

Changelog:

  • DyLib now detects the OS file extension
  • Check for defined(_WIN32) or defined(_WIN64)
  • Add noexcept keyword when it was possible
dylib - 1.2

Published by martin-olivier over 3 years ago

Changelog:

  • handle nullptr as argument
  • m_openLib for windows is now static
Badges
Extracted from project README
version license cpp ci coverage