Skip to content

Commit

Permalink
Added draft doc on CMake integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
yugr committed Feb 17, 2024
1 parent a6afbf2 commit 65355e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Implib.so provides an easy solution - link your program with a _wrapper_ which

Generated wrapper code (often also called "shim" code or "shim" library) is analogous to Windows import libraries which achieve the same functionality for DLLs.

Implib.so can also be used to [reduce API provided by existing shared library](doc/ReduceLibraryInterface.md) or [rename it's exported symbols](doc/RenameLibraryInterface.md).
Implib.so can also be used to [reduce API provided by existing shared library](doc/ReduceLibraryInterface.md) or [rename it's exported symbols](doc/RenameLibraryInterface.md). See [this page](doc/CMakeIntegration.md) for info on integrating Implib.so into a CMake project.

Implib.so was originally inspired by Stackoverflow question [Is there an elegant way to avoid dlsym when using dlopen in C?](https://stackoverflow.com/questions/45917816/is-there-an-elegant-way-to-avoid-dlsym-when-using-dlopen-in-c/47221180).

Expand Down
28 changes: 28 additions & 0 deletions doc/CMakeIntegration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
If your CMake project links to some library which you would like to replace with Implib.so wrapper:
```
cmake_minimum_required(VERSION 3.21)
project(prog)
add_executable(prog prog.c)
target_link_libraries(prog PRIVATE xcb)
```
you just need to add a custom command to generate wrapper code and link against `libdl`:
```
cmake_minimum_required(VERSION 3.21)
project(prog)
enable_language(ASM)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libxcb.so.tramp.S ${CMAKE_CURRENT_BINARY_DIR}/libxcb.so.init.c
COMMAND implib-gen.py /usr/lib/x86_64-linux-gnu/libxcb.so
DEPENDS /usr/lib/x86_64-linux-gnu/libxcb.so
)
add_executable(prog prog.c ${CMAKE_CURRENT_BINARY_DIR}/libxcb.so.tramp.S ${CMAKE_CURRENT_BINARY_DIR}/libxcb.so.init.c)
target_link_libraries(prog PRIVATE dl)
```

0 comments on commit 65355e3

Please sign in to comment.