[NTLUG:Discuss] C++ calls Java which calls C++

steve sjbaker1 at airmail.net
Mon May 22 20:53:11 CDT 2006


I'm trying to add some Java scripting into a program I wrote
ages ago (a game) so that my kid and his class of budding 9th
grade Java progammers can use it for practicing programming
in an environment that might be fractionally interesting to
15 yr olds.  Bear in mind that I'm a complete newb at Java
although I can write C++ in my sleep.

What I need to do is to have the C++ game code associate a
short Java program with each 'character' in the game - and
give the Java code C++ functions it can call to move the
character around...shoot...stuff like that.

So, obviously I'm using JNI to create a JVM - and I have
sucessfully loaded a number of little Java programs that
I can call from within C++.  This all works just great.

Next, I need to call some C++ service functions from within
the Java code.

The only way I can seem to get this to work is to have
the Java code load up a C++ ".so" library using

    System.load("libWhatever.so")
,..or...
    System.loadLibrary("Whatever")

...both of which load up libWhatever.so and allow me
to call C++ functions within that library.

So far, so good.  The problem is that functions inside
libWhatever.so don't seem to be able to call functions
in the main C++ program.   This is a major problem.

Any ideas?  What is the JVM/JNI doing when it links
to a library that C++ wouldn't do using
dlOpen/dlSym/dlClose?




More information about the Discuss mailing list