Arch Linux is a fantastic Linux distribution for developers, but it’s not without flaws. When I tried to create a portable executable by statically linking all its dependencies, the linker couldn’t find the static libraries. It turns out that since around 2013, Arch Linux stopped shipping pre-built static libraries.

The solution? Build the static libraries by ourselves using the Arch Linux Build System (ABS). Here’s a concise summary of the steps

  1. Fetch the source package
  2. Modify the build options to enable static libraries
  3. Build the package
  4. Install the package
  5. Pin the package to prevent upgrades from overwriting it.

it sounds easy. but the evil is in the details. Below I’ll walk through a completed example of building static libraries for libev using ABS

1. Fetch the source package

First, install the required tools

$ sudo pacman -S base-devel devtools

Then, fetch the PKGBUILD file for libev

$ pkgctl repo clone --protocol=https libev
==> Cloning libev ...
Cloning into 'libev'...
remote: Enumerating objects: 96, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 96 (delta 0), reused 0 (delta 0), pack-reused 91 (from 1)
Receiving objects: 100% (96/96), 13.58 KiB | 42.00 KiB/s, done.
Resolving deltas: 100% (23/23), done.
==> Collecting packager identity from makepkg.conf
  -> name    : undefined
  -> email   : undefined
  -> gpg-key : undefined
  -> protocol: https
==> Configuring libev

You will find the PKGBUILD file in the newly created libev directory

2. Modify the build options

Edit the PKGBUILD file to enable static libraries, Here’s the diff

--- PKGBUILD
+++ PKGBUILD
@@ -14,11 +14,12 @@ provides=('libev.so')
source=(http://dist.schmorp.de/${pkgname}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('c662a65360115e0b2598e3e8824cf7b33360c43a96ac9233f6b6ea2873a10102551773cad0e89e738541e75af9fd4f3e3c11cd2f251c5703aa24f193128b896b')
b2sums=('8a6cae25ffde10b24a5bbf084f6a8559af326b37acdbdf47dda34b7f0c7955f3ebd26958594444a574cfa3e2b4011e4be93ad2bd994ffd4c094bf36620e67ba5')
+options=(staticlibs)

build() {
    cd ${pkgname}-${pkgver}
-   ./configure --prefix=/usr
+   ./configure --prefix=/usr --enable-static
    make
}
  • Added options=('staticlibs') to enable static library generation.
  • Added --enable-static to the configure command.

3. Build the Package

Run the makepkg command

$ makepkg
==> Making package: libev 4.33-3 (Tue Mar 11 23:24:34 2025)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Found libev-4.33.tar.gz
==> Validating source files with sha512sums...
    libev-4.33.tar.gz ... Passed
==> Validating source files with b2sums...
    libev-4.33.tar.gz ... Passed
==> Extracting sources...
  -> Extracting libev-4.33.tar.gz with bsdtar
==> Starting build()...
checking for a BSD-compati
...
checking whether to build static libraries... yes
...

If the makepkg complains about missing dependencies, using --syncdeps flag to install them

$ sudo makepkg --syncdeps

4. Install the package

Install the built package

$ sudo makepkg --install

Alternatively, use pacman directly

$ sudo pacman -U libev-4.33-3-x86_64.pkg.tar.zst

5. Pin the package

To prevent system upgrades from overwriting your custom package. edit ~/etc/pacman.conf. Uncomment the IgnorePkg line, and add libev

IgnorePkg=libev