{"id":16642915,"url":"https://github.com/martin-olivier/dylib","last_synced_at":"2025-04-05T18:12:05.917Z","repository":{"id":36957455,"uuid":"354428648","full_name":"martin-olivier/dylib","owner":"martin-olivier","description":"C++ cross-platform wrapper around dynamic loading of shared libraries (dll, so, dylib)","archived":false,"fork":false,"pushed_at":"2024-08-01T11:01:21.000Z","size":232,"stargazers_count":294,"open_issues_count":5,"forks_count":45,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-13T08:05:50.164Z","etag":null,"topics":["cpp","dl","dll","dlopen","dlsym","dylib","dynamic-libraries","dynamic-library","library","shared-libraries","shared-library","so","wrapper"],"latest_commit_sha":null,"homepage":"https://conan.io/center/recipes/dylib","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martin-olivier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-04T01:11:44.000Z","updated_at":"2024-10-11T05:09:04.000Z","dependencies_parsed_at":"2023-10-20T21:39:25.226Z","dependency_job_id":"625643cb-41c3-4fb0-a0e1-dc6c09ff26a5","html_url":"https://github.com/martin-olivier/dylib","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-olivier%2Fdylib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-olivier%2Fdylib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-olivier%2Fdylib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martin-olivier%2Fdylib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martin-olivier","download_url":"https://codeload.github.com/martin-olivier/dylib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378152,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","dl","dll","dlopen","dlsym","dylib","dynamic-libraries","dynamic-library","library","shared-libraries","shared-library","so","wrapper"],"created_at":"2024-10-12T08:06:22.890Z","updated_at":"2025-04-05T18:12:05.896Z","avatar_url":"https://github.com/martin-olivier.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# dylib\n\n[![version](https://img.shields.io/badge/Version-2.2.1-blue.svg)](https://github.com/martin-olivier/dylib/releases/tag/v2.2.1)\n[![license](https://img.shields.io/badge/License-MIT-orange.svg)](https://github.com/martin-olivier/dylib/blob/main/LICENSE)\n[![cpp](https://img.shields.io/badge/Compatibility-C++11-darkgreen.svg)](https://isocpp.org)\n\n[![ci](https://github.com/martin-olivier/dylib/actions/workflows/CI.yml/badge.svg)](https://github.com/martin-olivier/dylib/actions/workflows/CI.yml)\n[![coverage](https://codecov.io/gh/martin-olivier/dylib/branch/main/graph/badge.svg)](https://codecov.io/gh/martin-olivier/dylib)\n\nThe goal of this C++ library is to load dynamic libraries (.so, .dll, .dylib) and access its functions and global variables at runtime.  \n\n`⭐ Don't forget to put a star if you like the project!`\n\n## Compatibility\n\nWorks on `Linux`, `MacOS` and `Windows`\n\n## Installation\n\n### Using a package manager\n\nYou can install `dylib` from [vcpkg](https://vcpkg.io/en) or [conan center](https://conan.io/center):\n\n```sh\nvcpkg install dylib\n```\n\n```sh\nconan install --requires=dylib/2.2.1\n```\n\n### Using CMake Fetch\n\nYou can also fetch `dylib` to your project using `CMake`:\n\n```cmake\ninclude(FetchContent)\n\nFetchContent_Declare(\n    dylib\n    GIT_REPOSITORY \"https://github.com/martin-olivier/dylib\"\n    GIT_TAG        \"v2.2.1\"\n)\n\nFetchContent_MakeAvailable(dylib)\n```\n\n## Documentation\n\n### Constructor\n\nThe `dylib` class can load a dynamic library from the system library path\n\n```c++\n// Load \"foo\" library from the system library path\n\ndylib lib(\"foo\");\n```\n\nThe `dylib` class can also load a dynamic library from a specific path\n\n```c++\n// Load \"foo\" library from relative path \"./libs\"\n\ndylib lib(\"./libs\", \"foo\");\n\n// Load \"foo\" library from full path \"/usr/lib\"\n\ndylib lib(\"/usr/lib\", \"foo\");\n```\n\nThe `dylib` class will automatically add the filename decorations of the current os to the library name, but you can disable that by setting `decorations` parameter to `dylib::no_filename_decorations`\n\n```c++\n// Windows -\u003e \"foo.dll\"\n// MacOS   -\u003e \"libfoo.dylib\"\n// Linux   -\u003e \"libfoo.so\"\n\ndylib lib(\"foo\");\n\n// Windows -\u003e \"foo.lib\"\n// MacOS   -\u003e \"foo.lib\"\n// Linux   -\u003e \"foo.lib\"\n\ndylib lib(\"foo.lib\", dylib::no_filename_decorations);\n```\n\n### Get a function or a variable\n\n`get_function`  \nGet a function from the dynamic library currently loaded in the object  \n\n`get_variable`  \nGet a global variable from the dynamic library currently loaded in the object\n\n```c++\n// Load \"foo\" dynamic library\n\ndylib lib(\"foo\");\n\n// Get the function \"adder\" (get_function\u003cT\u003e will return T*)\n\nauto adder = lib.get_function\u003cdouble(double, double)\u003e(\"adder\");\n\n// Get the variable \"pi_value\" (get_variable\u003cT\u003e will return T\u0026)\n\ndouble pi = lib.get_variable\u003cdouble\u003e(\"pi_value\");\n\n// Use the function \"adder\" with \"pi_value\"\n\ndouble result = adder(pi, pi);\n```\n\n### Miscellaneous tools\n\n`has_symbol`  \nReturns true if the symbol passed as parameter exists in the dynamic library, false otherwise\n\n`get_symbol`  \nGet a symbol from the dynamic library currently loaded in the object  \n\n`native_handle`  \nReturns the dynamic library handle\n\n```c++\ndylib lib(\"foo\");\n\nif (lib.has_symbol(\"GetModule\") == false)\n    std::cerr \u003c\u003c \"symbol 'GetModule' not found in 'foo' lib\" \u003c\u003c std::endl;\n\ndylib::native_handle_type handle = lib.native_handle();\ndylib::native_symbol_type symbol = lib.get_symbol(\"GetModule\");\n\nassert(handle != nullptr \u0026\u0026 symbol != nullptr);\nassert(symbol == dlsym(handle, \"GetModule\"));\n```\n\n### Exceptions\n\n`load_error`  \nThis exception is raised when the library failed to load or the library encountered symbol resolution issues  \n\n`symbol_error`  \nThis exception is raised when the library failed to load a symbol  \n\nThose exceptions inherit from `dylib::exception`\n\n```c++\ntry {\n    dylib lib(\"foo\");\n    double pi_value = lib.get_variable\u003cdouble\u003e(\"pi_value\");\n    std::cout \u003c\u003c pi_value \u003c\u003c std::endl;\n} catch (const dylib::load_error \u0026) {\n    std::cerr \u003c\u003c \"failed to load 'foo' library\" \u003c\u003c std::endl;\n} catch (const dylib::symbol_error \u0026) {\n    std::cerr \u003c\u003c \"failed to get 'pi_value' symbol\" \u003c\u003c std::endl;\n}\n```\n\n## Example\n\nA full example about the usage of the `dylib` library is available [HERE](example)\n\n## Tests\n\nTo build unit tests, enter the following commands:\n\n```sh\ncmake . -B build -DDYLIB_BUILD_TESTS=ON\ncmake --build build\n```\n\nTo run unit tests, enter the following command inside `build` directory:\n\n```sh\nctest\n```\n\n## Community\n\nIf you have any question about the usage of the library, do not hesitate to open a [discussion](https://github.com/martin-olivier/dylib/discussions)\n\nIf you want to report a bug or provide a feature, do not hesitate to open an [issue](https://github.com/martin-olivier/dylib/issues) or submit a [pull request](https://github.com/martin-olivier/dylib/pulls)\n\n## Contributing\n\nSet the cmake flag `DYLIB_BUILD_TESTS` to `ON` to enable tests and make it easier for you to contribute\n\n```sh\ncmake . -B build -DDYLIB_BUILD_TESTS=ON\n```\n\n\u003e Do not forget to sign your commits and use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) when providing a pull request\n\n```sh\ngit commit -s -m \"feat: ...\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin-olivier%2Fdylib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartin-olivier%2Fdylib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartin-olivier%2Fdylib/lists"}