This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Calling java code from C/C++ code.
- To: tromey at redhat dot com
- Subject: Re: Calling java code from C/C++ code.
- From: Timothy Wall <twall at oculustech dot com>
- Date: Tue, 27 Feb 2001 14:12:58 -0500
- CC: java at gcc dot gnu dot org
- Organization: Oculus Technologies
- References: <3A9BE61C.3F2936FC@cygnus.com> <87u25grna6.fsf@creche.redhat.com>
- Reply-To: twall at oculustech dot com
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