I am working on a platform where I compile the Roc code into a shared library and then build the final executable using cargo. Right now I can correctly access Roc functions defined in Roc, but functions like roc_realloc
are not being linked properly:
nm libapp.so.1
...
000000000000c380 T roc__mainForHost_1_exposed_size
U roc_panic
U roc_realloc
000000000000f8d0 t Str_concat_7a93171d29c34145ace0bed7f158bc6f747d259f21a8119f90767f874eb48b94
...
Does anyone have ideas about what I might be doing wrong?
Here's the source
Is the entire platform a shared library or just the roc code?
Just the roc code
So roc_alloc and friends should be provided by the host binary that loads the shared library
This is where passing in an explicit allocator would make this easier. Then you just pass it in instead of dealing with linking
In this case, you need to make sure your rust app exposes those dynamic symbols for roc to depend on.
I'm still a Roc beginner, but my conceptual understanding of the use-case here is that (i) the actual platform that's being used to compile the Roc code into a shared library and (ii) the final executable (i.e., a "host" in a way), could be both viewed as platform instances conforming to the same minimal interface which includes roc_realloc
et al.
I imagine, if the implementations of roc_realloc
et al differ semantically (in obvious - or not so much - ways) between the two platforms, this could lead to some unexpected behaviour down the line.
In this case, you need to make sure your rust app exposes those dynamic symbols for roc to depend on.
I’ll look into this, thanks!
This is where passing in an explicit allocator would make this easier. Then you just pass it in instead of dealing with linking
I’m not sure I understand this. How would this help/where would the allocator be passed?
I imagine, if the implementations of
roc_realloc
et al differ semantically (in obvious - or not so much - ways) between the two platforms, this could lead to some unexpected behaviour down the line.
There is just one platform here so that won’t be an issue.
Instead of dealing with this linking stuff. roc__mainForHost...
would just take a struct of function pointers as an argument.
Ah yeah that would be cool!
Adding RUSTFLAGS="-C link-args=-rdynamic"
did the trick! :smiley:
As a note, that will limit dead code elimination (IIRC). There are ways to specify specific symbols to expose that work better if that becomes an issue for you.
Good to know :check:
Last updated: Jul 26 2025 at 12:14 UTC