To build and install the oblibs project, you need:
-
A POSIX-compliant C development environment (conforming to POSIX.1-2008, available at Open Group).
-
Mesonversion1.1.0or later: mesonbuild.com. -
Ninja(typically installed with Meson). -
skalibsversion2.14.3.0or later: skarnet.org/software/skalibs. -
execlineversion2.9.6.1or later: skarnet.org/software/execline. -
Linux API headers version 5.8 or later (required for Linux systems): gnu.org/software/libc.
The software is designed to install on any operating system implementing POSIX.1-2008.
For most users, the following commands will configure, build, and install the oblibs project with default settings:
meson setup build
meson compile -C build
meson install -C buildThis installs:
- Shared libraries (e.g., liboblibs.so) to
/usr/lib(or the system’s library directory). - Header files to
/usr/include/oblibs.
To reduce binary size, you can strip symbols before installation:
meson compile -C build --strip
meson install -C buildYou can customize the build using Meson options. To see all available options, run:
meson configure buildExample customization:
meson setup build -D prefix=/usr/local -D enable-shared=false -D enable-static=true -D enable-static-deps=true -D tests=true
meson compile -C build
meson install -C buildwith-pkgconfig: Build and install a/usr/lib/pkgconfig/liboblibs.pcfile(default:false).enable-shared: Build shared libraries (e.g.,liboblibs.so) for dynamic linking (default:true).enable-static: Build static libraries (e.g.,liboblibs.a) for static linking (default:false).enable-static-deps: Prefer static linking for dependencies (e.g.,skalibs,s6) to reduce runtime dependencies; requires-D enable-static=true(default:false).enable-static-executable: Build fully static executables, including a staticlibc, for maximum portability; requires a staticlibc(e.g.,libc.a) on the system (default:false).enable-all-pic: Compile static libraries with position-independent code (PIC) for use in shared libraries orPIEexecutables (default:false).enable-pie: Build executables as position-independent (PIE) for enhanced security via Address Space Layout Randomization (ASLR) (default:false).test: Build and run tests (default:false).
- You can enable both
enable-sharedandenable-staticto build both shared and static libraries. enable-static-depsrequiresenable-static=trueto ensureliboblibs.ais built.enable-static-executableconflicts withenable-sharedand requires a staticlibc.enable-static-depsconflicts withenable-shareddue to incompatible linking models.enable-pieis compatible with most options but may not work withenable-static-executableon some systems due to toolchain limitations.enable-all-picapplies only to static libraries and is compatible with all options.
Meson supports a few environment variables for build customization, but passing options directly to meson setup is preferred for clarity:
-
CC: Overrides the compiler (e.g.,CC=clang meson setup build). When cross-compiling, the--cross-fileoption may prefix the compiler with the target triplet. -
CFLAGS,CPPFLAGS, LDF`LAGS: Appended to Meson’s default flags. To override defaults, use Meson options or build variables instead.
You can pass variables to meson compile or meson install for fine-grained control:
CC,CFLAGS,CPPFLAGS,LDFLAGS,LDLIBS: Override compiler, flags, or libraries.AR,RANLIB,STRIP,INSTALL: Customize archiver, ranlib, strip, or install tools.DESTDIR: Specify a staging directory for installation.
Example:
CFLAGS="-O3 -march=native" meson compile -C build
DESTDIR=/tmp/staging meson install -C buildBy default, executables are linked dynamically with libc and other dependencies, even if enable-static is used. To build fully static executables (including a static libc):
-
Use
enable-static-executable. This requires a staticlibc(e.g.,libc.a) on the system, such aslibc6-dev(Debian/Ubuntu),glibc-static(Fedora), ormusl-dev(Alpine Linux). -
Note: GNU
libcproduces larger static binaries compared to alternatives likemusl. For smaller, portable binaries, consider usingmusl.
To reduce runtime dependencies without fully static executables, use enable-static-deps with enable-static=true to link dependencies (e.g., skalibs, execline) statically.
Cross-compilation is simplified once skalibs is built for the target platform.
To cross-compile:
- Create a Meson cross file (e.g.,
cross-file.ini) specifying the target triplet (e.g.,arm-linux-gnueabihf) and toolchain paths. - Ensure the cross-toolchain binaries (e.g.,
arm-linux-gnueabihf-gcc) are in yourPATH. - Use the correct
skalibssysdeps directory for the target, specified viasysdeps-dir. - Customize include and library paths with
with-include-dir,with-staticlib-dir, andwith-dynamiclib-dirif needed.
Example:
meson setup build --cross-file=cross-file.ini -D sysdeps-dir=/path/to/target/sysdeps
meson compile -C build
meson install -C buildThe build generates a liboblibs.pc file for use with with-pkgconfig, installed to ${libdir}/pkgconfig (e.g., /usr/lib/pkgconfig). To link against liboblibs:
pkg-config --cflags --libs liboblibs-
If
enable-static-executableis enabled, the build will fail with a clear error if a staticlibcis not found. Ensure the appropriate development package is installed (e.g.,libc6-dev,musl-dev). -
If
enable-static-depsis enabled withoutenable-static, the build will fail to ensureliboblibs.ais available. -
For security-sensitive systems, consider enabling
enable-pieto benefit fromASLR.