The static site generation platform I'm working on has a file watcher which rebuilds the site if a source file changes. I'd also like to rebuild if the main.roc
file which contains the build rules changes. To do that currently I'm letting the host exec
into a fresh roc run ..
call on main.roc
, but this means that if there's compiler errors the file watching process will exit.
I'm trying to change this logic to instead run roc build --lib main.roc
in a spawned process, then dlopen
the shared library roc outputs. I'm running into a problem though: dlopen
fails saying roc_alloc
could not be found. That sort of makes sense, roc_alloc
is defined in the binary that's currently running and which is calling dlopen
.
From searching I've learned that the -rdynamic
linker flag exists for this precise purpose, and I've enabled it in my build.zig
file for the linker=legacy
library I'm building. (I haven't had luck using the surgical linker for this platform since a while ago, so it's out of the picture). Even with -rdynamic
set the linker error is still there.
I'm still learning about linking so was hoping someone might be able to confirm/reject this hypothesis: Could it be that this is because the linking that Roc performs as part of building the final binary overrules me setting rdynamic
on the library I build? If so, is there currently a way to tell the legacy linker it should be using the rdynamic
option?
If it doesn't work out I can go back to using the exec
option for now, I'm just curious and looking to learn :smile:
If you are using --lib
it shouldn't be using the legacy linker at all
As for -rdynamic
my guess is that zig is helpfully garbage collecting your unused code
As such, roc_alloc
and friends are not available
Frankly, rdynamic is kinda a hack anyway and I'm glad we plan to make more things explicit to avoid these pains
Ah yeah, it makes sense that --lib
wouldn't be using the linker.
Shouldn't zig leave roc_alloc
alone, since it's explicitly marked as an extern
fn and zig can't know what the artifact it produces might get linked with later?
Frankly, rdynamic is kinda a hack anyway and I'm glad we plan to make more things explicit to avoid these pains
Yeah, reading the new plans it sounds like things will be decidedly less magical in the future. Exciting times!
When making executables extern is often a lie
Cause the executable is seen as the final thing
Last updated: Jul 06 2025 at 12:14 UTC