A simple C shared library (libhello) built while learning how dynamic linking and library packaging work with CMake.
Hello_lib is a minimal "hello world" style shared library. It exists as a learning project for understanding:
- How to structure a C library (
include/+src/) - Building and installing a shared library with CMake
- Linking an external program against that shared library
Hello_lib/
├── include/ # Public header (hello.h)
├── src/ # Library source code
├── Example/ # Sample program that links against libhello
├── CMakeLists.txt # Build configuration
└── .gitignore
On Termux, set the install prefix explicitly so the library installs into your environment:
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$PREFIXOn other Linux systems, you can omit -DCMAKE_INSTALL_PREFIX to use the default prefix, or set your own.
cmake --build buildcmake --install buildThis installs:
| File | Destination |
|---|---|
hello.h |
$PREFIX/include |
libhello.so |
$PREFIX/lib |
The Example/ folder contains a small program demonstrating how to use the library.
Build it:
cd Example
gcc main.c -lhello -o helloRun it:
./hello SubhransuOutput:
Hello Subhransu.
Nice to meet you.
To remove the installed library:
cmake --build build --target uninstallThis project was built as a hands-on exercise in creating and consuming a C shared library — covering headers, dynamic linking, CMake install rules, and packaging a reusable component.