← All posts

OpenWrt UCI dependencies: runtime vs build time

Grow through practice

No need to finish reading — test now

One line: UCI's runtime dependency chain is short: libuci → libubox (+ libc); ubus/procd are dependencies of the OpenWrt integration layer, not of UCI itself.

Separate three scenarios

  1. Running the uci command;
  1. Building UCI itself;
  1. Writing a program that links libuci.

The Lua binding is an optional fourth case.

Runtime: a very short dependency chain

/sbin/uci
  ├─ libuci.so
  │    └─ libubox.so
  └─ libc

The OpenWrt package relationships are explicit:

PackageDependsNote
uci+libuci/sbin/uci
libuci+libuboxlibuci.so
libuci-lua+libuci +libluaoptional, /usr/lib/lua/uci.so

Therefore:

  • uci binary → libuci → libubox;
  • without ubus/procd, uci can still parse/edit/commit config files;
  • reload_config and /etc/init.d/* are what need the OpenWrt integration layer (base-files/procd/service scripts).

Note: readelf -d lists only direct dependencies — uci directly NEEDs libuci and libc; libubox is a direct dependency of libuci, and only ldd expands the whole chain.

UCI itself has no daemon: it is a one-shot CLI plus a library. The config directory is /etc/config; the staging directory is /tmp/.uci (both are compile-time constants in uci.h).

Build time: building UCI

UCI uses CMake; the core requirements are:

  • CMake ≥ 3.13;
  • C99 (the source uses -std=gnu99);
  • libubox headers and library (FIND_PATH looks for libubox/usock.h; FIND_LIBRARY looks for ubox);
  • Lua headers/libs only when BUILD_LUA=ON.

Main CMake options:

OptionDefaultPurpose
BUILD_LUAONbuild the Lua binding
BUILD_STATICOFFstatic linking (uses libubox.a)
UCI_DEBUGOFFdebug support
UCI_DEBUG_TYPECASTOFFruntime typecast checking
ABIVERSIONset by packagingABI version of libuci.so
UCI_PREFIXinstall prefixcompiled into uci_config.h

Build outputs:

  • libuci.so (libuci.c file.c util.c delta.c parse.c blob.c);
  • uci (cli.c);
  • libucimap.a (ucimap.c);
  • optional lua/uci.so.

OpenWrt packaging:

  • include $(INCLUDE_DIR)/cmake.mk;
  • libuci has DEPENDS:=+libubox;
  • libuci-lua has DEPENDS:=+libuci +liblua;
  • current main uses PKG_ABI_VERSION=20250120 (check your branch).

On a PC, build in order: libubox first, then UCI.

# 1) libubox
cmake -S libubox -B libubox/build \
  -DBUILD_LUA=OFF -DBUILD_EXAMPLES=OFF \
  -DCMAKE_INSTALL_PREFIX=/tmp/ubox-install
cmake --build libubox/build -j4
cmake --install libubox/build

# 2) UCI
cmake -S uci -B uci/build \
  -DBUILD_LUA=OFF \
  -DCMAKE_PREFIX_PATH=/tmp/ubox-install \
  -DCMAKE_INSTALL_PREFIX=/tmp/uci-install
cmake --build uci/build -j4
cmake --install uci/build

To run locally, add the install directories to the dynamic loader path:

export LD_LIBRARY_PATH=/tmp/uci-install/lib:/tmp/ubox-install/lib

Build time: writing a program with libuci

#include <uci.h>

uci.h includes the generated uci_config.h; compile-time constants live there:

  • UCI_CONFDIR "/etc/config"
  • UCI_SAVEDIR "/tmp/.uci"
  • UCI_PREFIX (injected by CMake)

Link:

cc -o demo demo.c -luci -lubox

Common APIs:

  • uci_alloc_context / uci_free_context
  • uci_load
  • uci_lookup_ptr
  • uci_set / uci_delete
  • uci_commit

A pitfall that actually crashes: uci_lookup_ptr takes a char *str that uci_parse_ptr splits in place with strsep; do not pass a string literal:

struct uci_ptr ptr;
char path[] = "network.wan.proto";   // not "network.wan.proto"
uci_lookup_ptr(ctx, &ptr, path, true);

With a literal it SIGSEGVs inside strsep (writing to a read-only segment). This is a PC measurement, not theory.

ABI matters: libuci.so carries an ABI version (e.g. 20250120); the cross-compiled library and the on-device runtime must match, or you get symbol/version problems.

Three commonly confused points

  1. uci does not depend on ubus/procd.

What depends on them is reload_config, init scripts, and the services themselves — not UCI's parse/commit.

  1. libuci depends on libubox, not the other way around.

libubox provides basic containers/IO; UCI is a consumer.

  1. The Lua binding is optional.

BUILD_LUA=OFF does not affect the CLI or the C API; install libuci-lua only when needed.

Check on a device

ldd /sbin/uci
opkg depends uci
opkg depends libuci
opkg files libuci
readelf -d /sbin/uci | grep NEEDED

Output varies by version/architecture; trust the target device.

PC test (Ubuntu 22.04.5)

Reproducible scripts (build.sh / test.sh / GitHub Actions): openwrt-uci-pc-demo.

Environment: gcc 11.4.0, CMake 4.4.4, libubox da2d205 (2026-10-08), UCI 74f6277 (2025-08-29), BUILD_LUA=OFF.

Dependency chain:

$ ldd /tmp/uci-install/bin/uci
libuci.so => /tmp/uci-install/lib/libuci.so
libubox.so => /tmp/ubox-install/lib/libubox.so
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6

$ readelf -d /tmp/uci-install/bin/uci | grep NEEDED
libuci.so
libc.so.6

$ readelf -d /tmp/uci-install/lib/libuci.so | grep NEEDED
libubox.so
libc.so.6

CLI (-c config dir, -t staging dir, so the system /etc/config is untouched):

$ uci -c /tmp/uci-conf -t /tmp/uci-save show network
network.wan=interface
network.wan.proto='dhcp'
network.wan.metric='10'

$ uci ... set network.wan.metric='20'
$ uci ... get network.wan.metric
20
$ uci ... changes network
network.wan.metric='20'
# the file still says 10

$ uci ... commit network
# the file now says 20; revert only discards uncommitted changes

Also verified: add_list, batch, anonymous-section add (prints the generated section name; show renders network.@route[0]), and -q get on a missing item returns 1.

C API: with uci_set_confdir / uci_set_savedir pointed at temporary dirs, uci_lookup_ptr read proto=dhcp; a string literal crashes in uci_parse_ptr (see above).

Verification status

  • ✅ source/packaging: CMakeLists.txt, uci.h, OpenWrt package/system/uci/Makefile;
  • ✅ PC test: built libubox + UCI on Ubuntu 22.04.5 (BUILD_LUA=OFF); ldd/readelf, show/get/set/changes/commit/revert/add_list/batch/add, and C-API read all pass;
  • ⚠️ not run on an OpenWrt device: opkg depends, procd/reload_config integration untested;
  • ❓ details: the exact libubox symbols and the purpose of UCI_CONF2DIR are not covered.

One sentence

UCI itself is small; the complexity is in the integration layer above it. Runtime: libuci → libubox; build time: CMake + C99 + libubox (Lua optional); ubus/procd are not UCI runtime dependencies.


Sources: openwrt/uci CMakeLists.txt · openwrt/uci uci.h · OpenWrt package/system/uci/Makefile · OpenWrt UCI technical reference Series: OpenWrt. Related: OpenWrt UCI: config files, commands, and boundaries.

Practice

Found this useful?

I write about AI agents × embedded / edge AI. Subscribe, or email me a concrete problem.

Guestbook →Subscribe (RSS)Support

Comments 0

No comments yet — be the first!

No login required; name is optional.