I'm writing a C++ plugin for an application. The plugin is a .o file. Call this code/functionality as being "C".
I also wrote a Java library. Think of the code and functionality as being "J".
Next I used JNI's Invocation API to allow C to call J. Now C can create objects, call methods, pass / receive values from Java objects or static methods. Conceptually:
C
JNI method call --------> J
C <----------- Result R
return R
Plugin C calls J via JNI. A useful value R is computed in J, returned to C, and eventually returned to the application.
I individually tested codes J, C, and JNI with "stub mains", and each piece works on its own. R is correct. The problem is when the plugin tries to create a VM using calls to JNI:
./myPlugin.so: undefined symbol: JNI_CreateJavaVM
I believe the problem is that my C++ .o file wants to dynamically link to libjvm.so, but either doesn't know how to, or something is preventing ld.so from linking at runtime.
When I ran JNI as its own code with a stub main (that is, I did essentially the same thing, but as an application with a main function rather than a .o file) the same thing happened, but it was clearly a matter of ld.so not being able to find libjvm.so. Defining:
export LD_LIBRARY_PATH=/usr/java/jdk1.8.0_73/jre/lib/amd64/server
allowed ld.so to do its job correctly. However, defining LD_LIBRARY_PATH to include the Java libs isn't working for my JNI code in the .o file.
Are the rules of dynamic linking different for object file libraries? Should I try to statically link libjvm.so into my .o file? How would one even go about doing that?
I'm on completely uncharted territory for me, and feeling a bit lost. Any help would be greatly appreciated!