OpenWrt UCI dependencies: runtime vs build time
Grow through practice
No need to finish reading — test nowOne line: UCI's runtime dependency chain is short:
libuci→libubox(+ libc);ubus/procdare dependencies of the OpenWrt integration layer, not of UCI itself.
Separate three scenarios
- Running the
ucicommand;
- Building UCI itself;
- 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:
| Package | Depends | Note |
|---|---|---|
uci | +libuci | /sbin/uci |
libuci | +libubox | libuci.so |
libuci-lua | +libuci +liblua | optional, /usr/lib/lua/uci.so |
Therefore:
ucibinary →libuci→libubox;- without
ubus/procd,ucican still parse/edit/commit config files; reload_configand/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_PATHlooks forlibubox/usock.h;FIND_LIBRARYlooks forubox); - Lua headers/libs only when
BUILD_LUA=ON.
Main CMake options:
| Option | Default | Purpose |
|---|---|---|
BUILD_LUA | ON | build the Lua binding |
BUILD_STATIC | OFF | static linking (uses libubox.a) |
UCI_DEBUG | OFF | debug support |
UCI_DEBUG_TYPECAST | OFF | runtime typecast checking |
ABIVERSION | set by packaging | ABI version of libuci.so |
UCI_PREFIX | install prefix | compiled 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;libucihasDEPENDS:=+libubox;libuci-luahasDEPENDS:=+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_contextuci_loaduci_lookup_ptruci_set/uci_deleteuci_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
ucidoes not depend onubus/procd.
What depends on them is reload_config, init scripts, and the services themselves — not UCI's parse/commit.
libucidepends onlibubox, not the other way around.
libubox provides basic containers/IO; UCI is a consumer.
- 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, OpenWrtpackage/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_configintegration untested; - ❓ details: the exact
libuboxsymbols and the purpose ofUCI_CONF2DIRare 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/procdare 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.
Comments 0
No comments yet — be the first!