Ruby Gem Build "error: implicit declaration of function" in CI
A gem’s C extension calls a function the compiler has no declaration for. Newer compilers (GCC 14+, recent clang) promote this from a warning to a hard error, so an older gem that compiled fine before now fails the build.
What this error means
A native gem build fails with "error: implicit declaration of function ‘X’", often a gem that built cleanly on an older toolchain. The error is at compile time, in the gem’s C source.
extension.c:120:7: error: implicit declaration of function 'strlcpy'
[-Wimplicit-function-declaration]
120 | strlcpy(buf, src, n);
| ^~~~~~~
make: *** [Makefile:245: extension.o] Error 1Common causes
Newer compiler rejects implicit declarations
GCC 14 and recent clang make implicit function declarations an error by default. Gem C code that relied on the old leniency no longer compiles on the newer toolchain.
Missing header that declares the function
The function is real but its header was not included (or a needed -dev package is missing), so the compiler sees no declaration and errors.
How to fix it
Update the gem to a toolchain-compatible version
Maintained gems have patched their C for newer compilers. Bumping the gem is the cleanest fix.
bundle update <gem>
bundle installInstall the missing header or relax the flag
- If a -dev package provides the missing declaration, install it (e.g. libbsd-dev for strlcpy on Linux).
- As a stopgap, build with -Wno-implicit-function-declaration (or -std=gnu89) via bundle config build.<gem> "--with-cflags=...".
- Prefer updating the gem over forcing the old behavior long term.
How to prevent it
- Keep gems updated to versions that compile on current compilers.
- Pin the runner compiler version if a gem is not yet compatible with the newest one.
- Prefer precompiled platform gems to avoid compiling C at all.