Skip to content

Commit

Permalink
Version 2.2.0 (#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Olivier <[email protected]>
  • Loading branch information
martin-olivier authored Oct 18, 2023
1 parent a111aea commit 84524ad
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 47 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
69 changes: 34 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
<h1 align="center">
dylib</h1>
<p align="center">
<a href="https://github.com/martin-olivier/dylib/releases/tag/v2.1.0">
<img src="https://img.shields.io/badge/Version-2.1.0-blue.svg" alt="version"/>
</a>
<a href="https://github.com/martin-olivier/dylib/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-orange.svg" alt="license"/>
</a>
<a href="https://isocpp.org/">
<img src="https://img.shields.io/badge/Compatibility-C++11-darkgreen.svg" alt="cppversion"/>
</a>
</p>

<p align="center">
<a href="https://github.com/martin-olivier/dylib/actions/workflows/CI.yml">
<img src="https://github.com/martin-olivier/dylib/actions/workflows/CI.yml/badge.svg" alt="ci"/>
</a>
<a href="https://codecov.io/gh/martin-olivier/dylib">
<img src="https://codecov.io/gh/martin-olivier/dylib/branch/main/graph/badge.svg?token=4V6A9B7PII" alt="codecov"/>
</a>
</p>
# 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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -106,7 +99,7 @@ double pi = lib.get_variable<double>("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
Expand All @@ -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");

Expand All @@ -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
Expand All @@ -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");
Expand All @@ -150,37 +145,41 @@ 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)

If 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)

## 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: ..."
```
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -114,6 +120,7 @@ Let's run our code:
```

You will have the following result:

```sh
15
Hello
Expand Down
4 changes: 2 additions & 2 deletions include/dylib.hpp
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @copyright (c) 2022 Martin Olivier
* @copyright (c) 2023 Martin Olivier
*
* This library is released under MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <utility>
#include "dylib.hpp"

TEST(exemple, exemple_test) {
TEST(example, example_test) {
testing::internal::CaptureStdout();
dylib lib("./", "dynamic_lib");

Expand Down

0 comments on commit 84524ad

Please sign in to comment.