diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index dd98411..3fd296a 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -47,7 +47,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Generate project files
run: cmake . -B build -G "${{ matrix.generator }}" -DCMAKE_CXX_STANDARD=${{ matrix.cxx-std }} -DDYLIB_BUILD_TESTS=ON -DDYLIB_WARNING_AS_ERRORS=ON
@@ -65,7 +65,7 @@ jobs:
- name: Send coverage to codecov.io
if: ${{ matrix.os == 'ubuntu-latest' && matrix.cxx-std == 20 }}
- uses: codecov/codecov-action@v2
+ uses: codecov/codecov-action@v3
with:
files: dylib.hpp.gcov
@@ -74,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Update packages
run: sudo apt update
@@ -97,7 +97,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v3
- name: Install cpplint
run: pip install cpplint
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 66bccc8..6f9689a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -71,7 +71,7 @@ endif()
set(CPACK_PACKAGE_NAME "dylib")
set(CPACK_PACKAGE_VENDOR "Martin Olivier")
set(CPACK_PACKAGE_VERSION_MAJOR "2")
-set(CPACK_PACKAGE_VERSION_MINOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "2")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION "C++ cross-platform wrapper around dynamic loading of shared libraries")
diff --git a/LICENSE b/LICENSE
index 1cc14c8..6000446 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2022 Martin Olivier
+Copyright (c) 2023 Martin Olivier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index d643443..c2c64bc 100644
--- a/README.md
+++ b/README.md
@@ -1,61 +1,52 @@
-
-dylib
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+# dylib
+
+[![version](https://img.shields.io/badge/Version-2.2.0-blue.svg)](https://github.com/martin-olivier/dylib/releases/tag/v2.2.0)
+[![license](https://img.shields.io/badge/License-MIT-orange.svg)](https://github.com/martin-olivier/dylib/blob/main/LICENSE)
+[![cpp](https://img.shields.io/badge/Compatibility-C++11-darkgreen.svg)](https://isocpp.org)
+
+[![ci](https://github.com/martin-olivier/dylib/actions/workflows/CI.yml/badge.svg)](https://github.com/martin-olivier/dylib/actions/workflows/CI.yml)
+[![coverage](https://codecov.io/gh/martin-olivier/dylib/branch/main/graph/badge.svg)](https://codecov.io/gh/martin-olivier/dylib)
The goal of this C++ library is to load dynamic libraries (.so, .dll, .dylib) and access its functions and global variables at runtime.
`⭐ Don't forget to put a star if you like the project!`
-# Compatibility
+## Compatibility
+
Works on `Linux`, `Windows`, `MacOS`
-# Installation
+## Installation
You can fetch `dylib` to your project using `CMake`:
+
```cmake
include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
- GIT_TAG "v2.1.0"
+ GIT_TAG "v2.2.0"
)
FetchContent_MakeAvailable(dylib)
```
-You can also click [HERE](https://github.com/martin-olivier/dylib/releases/download/v2.1.0/dylib.hpp) to download the `dylib` header file.
+You can also click [HERE](https://github.com/martin-olivier/dylib/releases/download/v2.2.0/dylib.hpp) to download the `dylib` header file.
-# Documentation
+## Documentation
-## Constructor
+### Constructor
The `dylib` class can load a dynamic library from the system library path
+
```c++
// Load "foo" library from the system library path
dylib lib("foo");
```
+
The `dylib` class can also load a dynamic library from a specific path
+
```c++
// Load "foo" library from relative path "./libs"
@@ -67,6 +58,7 @@ dylib lib("/usr/lib", "foo");
```
The `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`
+
```c++
// Windows -> "foo.dll"
// MacOS -> "libfoo.dylib"
@@ -81,13 +73,14 @@ dylib lib("foo");
dylib lib("foo.lib", dylib::no_filename_decorations);
```
-## Get a function or a variable
+### Get a function or a variable
`get_function`
Get a function from the dynamic library currently loaded in the object
`get_variable`
Get a global variable from the dynamic library currently loaded in the object
+
```c++
// Load "foo" dynamic library
@@ -106,7 +99,7 @@ double pi = lib.get_variable("pi_value");
double result = adder(pi, pi);
```
-## Miscellaneous tools
+### Miscellaneous tools
`has_symbol`
Returns true if the symbol passed as parameter exists in the dynamic library, false otherwise
@@ -116,6 +109,7 @@ Get a symbol from the dynamic library currently loaded in the object
`native_handle`
Returns the dynamic library handle
+
```c++
dylib lib("foo");
@@ -129,7 +123,7 @@ assert(handle != nullptr && symbol != nullptr);
assert(symbol == dlsym(handle, "GetModule"));
```
-## Exceptions
+### Exceptions
`load_error`
This exception is raised when the library failed to load or the library encountered symbol resolution issues
@@ -138,6 +132,7 @@ This exception is raised when the library failed to load or the library encounte
This exception is raised when the library failed to load a symbol
Those exceptions inherit from `dylib::exception`
+
```c++
try {
dylib lib("foo");
@@ -150,24 +145,26 @@ try {
}
```
-# Example
+## Example
A full example about the usage of the `dylib` library is available [HERE](example)
-# Tests
+## Tests
To build unit tests, enter the following commands:
+
```sh
cmake . -B build -DDYLIB_BUILD_TESTS=ON
cmake --build build
```
To run unit tests, enter the following command inside `build` directory:
+
```sh
ctest
```
-# Community
+## Community
If you have any question about the usage of the library, do not hesitate to open a [discussion](https://github.com/martin-olivier/dylib/discussions)
@@ -175,12 +172,14 @@ If you want to report a bug or provide a feature, do not hesitate to open an [is
## Contributing
-Set the cmake flag `DYLIB_BUILD_TESTS` to `ON` to enable tests and make it easier for you to contribute!
+Set the cmake flag `DYLIB_BUILD_TESTS` to `ON` to enable tests and make it easier for you to contribute
+
```sh
cmake . -B build -DDYLIB_BUILD_TESTS=ON
```
> Do not forget to sign your commits and use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) when providing a pull request
+
```sh
git commit -s -m "feat: ..."
```
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
index f60ad2f..69c636c 100644
--- a/example/CMakeLists.txt
+++ b/example/CMakeLists.txt
@@ -15,7 +15,7 @@ include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
- GIT_TAG "v2.1.0"
+ GIT_TAG "v2.2.0"
)
FetchContent_MakeAvailable(dylib)
diff --git a/example/README.md b/example/README.md
index fa76f0c..7f43b64 100644
--- a/example/README.md
+++ b/example/README.md
@@ -1,8 +1,9 @@
-# Dylib example
+# dylib example
Here is an example about the usage of the `dylib` library in a project
The functions and variables of our forthcoming dynamic library are located inside [lib.cpp](lib.cpp)
+
```c++
// lib.cpp
@@ -31,6 +32,7 @@ LIB_EXPORT void print_hello() {
```
The code that will load functions and global variables of our dynamic library at runtime is located inside [main.cpp](main.cpp)
+
```c++
// main.cpp
@@ -57,11 +59,13 @@ int main() {
```
Then, we want a build system that will:
+
- Fetch `dylib` into the project
- Build [lib.cpp](lib.cpp) into a dynamic library
- Build [main.cpp](main.cpp) into an executable
This build system is located inside [CMakeLists.txt](CMakeLists.txt)
+
```cmake
# CMakeLists.txt
@@ -82,7 +86,7 @@ include(FetchContent)
FetchContent_Declare(
dylib
GIT_REPOSITORY "https://github.com/martin-olivier/dylib"
- GIT_TAG "v2.1.0"
+ GIT_TAG "v2.2.0"
)
FetchContent_MakeAvailable(dylib)
@@ -99,12 +103,14 @@ target_link_libraries(dylib_example PRIVATE dylib)
Let's build our code:
> Make sure to type the following commands inside the `example` folder
+
```sh
cmake . -B build
cmake --build build
```
Let's run our code:
+
```sh
# on unix, run the following command inside "build" folder
./dylib_example
@@ -114,6 +120,7 @@ Let's run our code:
```
You will have the following result:
+
```sh
15
Hello
diff --git a/include/dylib.hpp b/include/dylib.hpp
index 06c8292..85bbadf 100644
--- a/include/dylib.hpp
+++ b/include/dylib.hpp
@@ -1,11 +1,11 @@
/**
* @file dylib.hpp
- * @version 2.1.0
+ * @version 2.2.0
* @brief C++ cross-platform wrapper around dynamic loading of shared libraries
* @link https://github.com/martin-olivier/dylib
*
* @author Martin Olivier
- * @copyright (c) 2022 Martin Olivier
+ * @copyright (c) 2023 Martin Olivier
*
* This library is released under MIT license
*/
diff --git a/tests/tests.cpp b/tests/tests.cpp
index 7377c0d..4906507 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -2,7 +2,7 @@
#include
#include "dylib.hpp"
-TEST(exemple, exemple_test) {
+TEST(example, example_test) {
testing::internal::CaptureStdout();
dylib lib("./", "dynamic_lib");