# Zig \`-fincremental\` requires C \`-fPIE\`? (and what to do about it)

**URL:** <https://ziggit.dev/t/zig-fincremental-requires-c-fpie-and-what-to-do-about-it/14562>\
**Category:** Help\
**Tags:** build-system\
**Created:** [March 9, 2026, 12:24pm UTC](https://ziggit.dev/t/zig-fincremental-requires-c-fpie-and-what-to-do-about-it/14562 "2026-03-09T12:24:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![floooh](https://ziggit.dev/user_avatar/ziggit.dev/floooh/32/2989_2.png) [@floooh](https://ziggit.dev/u/floooh)\
**Post date:** [March 9, 2026, 12:24pm UTC](https://ziggit.dev/t/zig-fincremental-requires-c-fpie-and-what-to-do-about-it/14562/1 "2026-03-09T12:24:53Z")

</div>

Interesting detail just popped up in the sokol-zig issue tracker: it looks like that Zig’s incremental compilation requires any C dependencies to be built as position-independent (`-fPIE`), otherwise a compiler crash happens with `thread 22765 panic: REX_GOTPCRELX` (in the non-LLVM x86 backend).

Compiling C deps with `-fPIE` seems to workaround that crash (haven’t tested that myself though), see the comments towards the end:

> <https://github.com/floooh/dcimgui/issues/10>
>
> Merely adding the dependency with \`zig fetch\` and
> \`\`\`Zig
> const dep\_cimgui = b.de…pendency("cimgui", .{
> .target = target,
> .optimize = optimize,
> });
> // ...
> exe.root\_module.addImport("cimgui", dep\_cimgui.module("cimgui"));
> \`\`\`
> 
> (not even importing cimgui in any Zig code) causes \`-fincremental\` to break with a \`REX\_GOTPCRELX\` panic:
> 
> \`\`\`
> zig-x86\_64-linux-0.16.0-dev.2040+c475f1fcd/zig build -fincremental
> install
> └─ install ztest
> └─ compile exe ztest Debug native failure
> error: Compiler crash context:
> (no context)
>        
> thread 22765 panic: REX\_GOTPCRELX
> Cannot print stack trace: stack tracing is disabled
>        
> error: process terminated with signal ABRT
> failed command: /tmp/zig-x86\_64-linux-0.16.0-dev.2040+c475f1fcd/zig build-exe -ODebug --dep ztest --dep cimgui -Mroot=/tmp/ztest/src/main.zig -Mztest=/tmp/ztest/src/root.zig .zig-cache/o/36a66aa2ac076684bdde282858c0d861/libcimgui\_clib.a -ODebug -I .zig-cache/o/338cd2ea29e602736b4685a31af3e3bb -Mcimgui=.zig-cache/o/2867f597525386bd49ddd89ef0b44e67/cimgui.zig -lc++ -lc --cache-dir .zig-cache --global-cache-dir /home/rafael/.cache/zig --name ztest --zig-lib-dir /tmp/zig-x86\_64-linux-0.16.0-dev.2040+c475f1fcd/lib/ -fincremental --listen=-
> 
> Build Summary: 3/6 steps succeeded (1 failed)
> install transitive failure
> └─ install ztest transitive failure
> └─ compile exe ztest Debug native failure
> 
> error: the following build command failed with exit code 1:
> .zig-cache/o/8a69d231c45e0381690127470a5f8d49/build /tmp/zig-x86\_64-linux-0.16.0-dev.2040+c475f1fcd/zig /tmp/zig-x86\_64-linux-0.16.0-dev.2040+c475f1fcd/lib /tmp/ztest .zig-cache /home/rafael/.cache/zig --seed 0x3d6fdea7 -Z380ab3440b9c6981 -fincremental
> \`\`\`
> 
> I initially ran into this in my other project which has a couple more dependencies and thought it was a bug in the self-hosted Zig compiler itself, but then managed to isolate it to only \`dcimgui\` by removing dependencies in a fresh test project one by one, and it appears this dep is the only one that causes this.
> 
> Is there some other inherent limitation in the Zig self-hosted compiler that I am not aware of that causes this by not playing nice with dcimgui?

…so regardless whether that’s a compiler bug or expected behaviour, that got me thinking how the build system of C dependencies should react to similar requirements from the Zig build (e.g. basically “if Zig build option X is enabled, C build option Y also needs to be enabled”).

Is the Zig build system implementation expected to take care of that (e.g. the build system would automatically inject an `-fPIE` into all C dependencies when the Zig code is built with `-fincremental`), or if the C dependency build system is expected to handle such cases, what’s the recommend way?

Adding a build option (e.g. `-D...`) isn’t really an option (heh), because that would need to be passed down the entire build tree explicitly, even into Zig dependencies which might theoretically depend on C dependencies.

Or maybe just build all C code as position-independent?

(also: related older ticket: [https://codeberg.org/ziglang/zig/issues/30780](https://codeberg.org/ziglang/zig/issues/30780))

---

<div class="post-metadata">

**Author:** ![andrewrk](https://ziggit.dev/user_avatar/ziggit.dev/andrewrk/32/7011_2.png) [@andrewrk](https://ziggit.dev/u/andrewrk)\
**Post date:** [March 9, 2026, 4:42pm UTC](https://ziggit.dev/t/zig-fincremental-requires-c-fpie-and-what-to-do-about-it/14562/2 "2026-03-09T16:42:37Z")

</div>

It’s just an incomplete linker. No need for all these workarounds we just need to finish it.
