How to test scala native code interop with C

Probably it fails because it cannot find HelloWorld.so, every extern function annotated (directly or having an annotated owner) is automatically added when linking as -l <name>, in the case of this code it would be -l HelloWorld.
If you only require a simple glue code, then you might consider placing C sources directly in resources/scala-native directory (see Native Code in your Application or Library — Scala Native 0.5.5 documentation although it might require adoption to the Mill build tool.)
If you require C code to be compiled outside Scala Native then remove @link annotation and pass .so path directly to linking options or ensure to inform linker where to find linked libraries (although the nativeLinkingOptions seems correct at first glance)

Can’t really help more without decent logs, probably most of these are hidden by mill. What we’re missing are stderr logs from clang that might give more context.

I’ve just seen these:

146] [info] Linking with [pthread, dl, HelloWorldBar]
[146] [error] /usr/bin/ld: cannot find -lHelloWorldBar: No such file or directory

There’s no HelloWorldBar defined anywhere in published snippets. Consider cleaning mill caches

2 Likes