C++ to Java to C++
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   eric_chang
Posted On:   Tuesday, May 14, 2002 01:40 PM

My team is currently working on integrating two C++ applications using a JNI bridge to work around naming conflicts that exist between the two C++ apps (and thus prevent us from compiling and running them as a single C++ app). The setup involves the following three modules: 1. C++ class Main.cpp , which runs as the main application and uses the Invocation API to create a JVM. 2. Java class Bridge.java , which is accessed through the invoked JVM and in turn, makes native calls to... 3. C++ class Modeler.cpp , which has been compiled into a shared library libmodeler.so some pertinent pseudo-code: Main.cpp: ...    More>>

My team is currently working on integrating two C++ applications using a JNI bridge to work around naming conflicts that exist between the two C++ apps (and thus prevent us from compiling and running them as a single C++ app). The setup involves the following three modules:

1. C++ class Main.cpp , which runs as the main application and uses the Invocation API to create a JVM.

2. Java class Bridge.java , which is accessed through the invoked JVM and in turn, makes native calls to...

3. C++ class Modeler.cpp , which has been compiled into a shared library libmodeler.so

some pertinent pseudo-code:

Main.cpp:

			
...
JNI_CreateJavaVM(&jvm,&env,&vm_args);
jclass bridge_class = env->FindClass(env,"Bridge");
...


Bridge.java:

			
public class Bridge {
static {
System.err.println("Loading modeler native library");
System.loadLibrary("modeler");
System.err.println("Done loading modeler native library");
}
....



We have verified the interaction between Bridge.java and the Modeler.cpp modules by running Bridge alone as a Java main. However, when Main.cpp is run as a C++ main, invokes a JVM, and then tries to find the Bridge java class, it seems to get to the first System.err.println() call but then simply returns from the call to System.loadLibrary without loading the library or printing out the System.err.println() call that immediately follows it. No java throwables (e.g., UnsatisfiedLinkError or SecurityException) are thrown, and no native errors occur either (e.g., seg fault).

Is this configuration even possible? What does it mean to make a call to System from a Java class that is running in a JVM that was invoked from C++? My guess is that dynamic library loading was not implemented in the C++ invocation API implementation, or (and maybe concurrently) since there is no facility in C++ to dynamically load a library, calls to System.loadLibrary() from with an invoked JVM are meaningless.

Thank you in advance for your responses.

   <<Less
About | Sitemap | Contact