dylib

dylib example

Here is an example about the usage of the dylib library in a project.

The functions and variables of our future dynamic library are located inside lib.cpp

The code that will load the functions and global variables of our dynamic library at runtime is located inside main.cpp

Then, our build system, located inside CMakeLists.txt, is performing the following tasks:

Let’s build our code:

Make sure to type the following commands inside the example folder

cmake . -B build
cmake --build build

Let’s run our code:

# on unix, run the following command inside "build" folder
./dylib_example

# on windows, run the following command inside "build/Debug" folder
./dylib_example.exe

You will have the following result:

Hello World!
dylib - v3.0.1
pi value: 3.14159
magic value: cafebabe
10 + 10 = 20
string = abcdef
vector:
- abc
- def
- ghi
- jkl
cb operation with (10, 5), using adder: 15