Search code examples
javacjava-native-interfaceglibvala

Java JNI and Vala - Undefined Symbol: g_once_init_enter


I wrote a tiny Vala class, compiled that to C code, generated JNI header and implementation to call the Vala / CCode from.

So at the end I have two headers and two implementation files which I compile with gcc to a JNI library. it compiles fine and results in a library.

When I run the Java app, including this library, I get symbol lookup error in the lib.

The interesting part is: undefined symbol: g_once_init_enter - it is not in my code, but in the glib code, generated by valac.

So, JNI C code calls Vala C code which calls glib stuff. Java seems to not find the glib part.

Anyone any idea, what to do here?


Solution

  • It appears this was a problem with Das Jott’s code to generate compiler command lines to generate C files, and it was fixed in this commit. It looks like they were trying to execute bash-style shell script using exec(), which resulted in the pkg-config flags for glib-2.0 never making it into the linker command line.

    tl;dr: As Samhain said, the root problem was failing to link against glib-2.0.