Skip to content
Latchkey

V "C error: undefined reference" at the cc step in CI

V transpiles to C and links the result with the system C compiler. An "undefined reference" at that step means a C symbol from a wrapped library has no definition because the library was not linked.

What this error means

The build fails after V finishes, with the cc/ld output showing "undefined reference to X" and "cannot find -l..." for a native library.

v
/usr/bin/ld: undefined reference to `sqlite3_open'
collect2: error: ld returned 1 exit status
builder error: C error. This should never happen.

Common causes

A wrapped C library was not linked

A module calls into a C library but the link flag for it was missing, so ld cannot resolve the C symbols.

The development library is not installed

The dev package providing the library and its headers is absent on the runner, so the link cannot find it.

How to fix it

Install the dev library and link it

  1. Install the -dev package for the C library the module wraps.
  2. Ensure the module declares the link flag (or pass it to the build).
  3. Re-run; the link succeeds once the library is found.
Terminal
sudo apt-get update && sudo apt-get install -y libsqlite3-dev

Pass the link flag to the C backend

Tell V to link the native library when the module does not declare it.

Terminal
v -cflags -lsqlite3 build .

How to prevent it

  • Install dev packages for every C library your modules wrap.
  • Declare link flags in modules that bind native libraries.
  • List native system dependencies in the CI setup step.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →