Enable self-describing libraries with a single command.
Lib²Info (or liblibinfo
) is a small addition to CMake to turn your shared libraries into stand-alone executables that still can be dynamically linked. It's small and can be copied into an existing project.
In order to use Lib²Info, you need to use CMake. Also, only GCC is currently supported. While it might work with Clang, that hasn't been tested yet.
Add liblibinfo.cmake
and liblibinfo.c.in
to your project, include(...)
the .cmake
file and then use the add_libinfo(TARGET)
function on a shared library:
cmake_minimum_required(VERSION 3.10)
project(libgen
VERSION 1.0.0
LANGUAGES C)
include("liblibinfo.cmake")
add_library(foo SHARED foo.c)
add_libinfo(foo)
Shared libraries on Linux systems are ELF files. With an appropriate entry in the .interp
section and a proper entry point it's possible to run them. The add_libinfo
call prepares an additional source file with a banner, entry point implementation and interpreter section. It also adjust the linker flags to configure the entry point.