Calling java code from C/C++ code.
Timothy Wall
twall@oculustech.com
Tue Feb 27 11:13:00 GMT 2001
I'm not sure what you mean. I'm using a java "main", e.g.
public class test {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}
The C++ wrapper code looks simliar to what gcj generates as a
"main"wrapper, I load this object and the one from the above code:
extern const char **_Jv_Compiler_Properties;
extern void JvRunMain(struct Class*, int, char**);
static const char *props[] = { 0 |;
extern struct Class _CL_4test;
extern "C" int callable(void)
{
_Jv_Compiler_Properties = props;
JvRunMain (&_CL_4test, 0, 0);
return 0;
}
So in effect, I'm invoking the java "main" (which is ok). However, the
dlopen fails in the static initializers as previously described.
Seeing that the shared object never gets loaded, I don't see how the
class implementation would make a difference.
Tim
Tom Tromey wrote:
> >>>>> "Tim" == Timothy Wall <twall@cygnus.com> writes:
>
> Tim> Is it possible to use gcj to generate a shared object which can
> Tim> be loaded (via dlopen/dlsym) and invoked from a C/C++ program?
>
> Not yet. We haven't finished the invocation API, which is what you
> would need to make this work.
>
> You could do it with a Java main() though. In fact it would probably
> work if your Java class' main() was a native method. (I haven't tried
> that but I don't see why it wouldn't work.)
>
> Tom
More information about the Java
mailing list