This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: GCJ and C++ (calling Java from C++)
On Tuesday 29 November 2005 09:42, Andrew Haley wrote:
> The first thing in Section 12.15, Invocation, is:
>
> Function: jint JvCreateJavaVM (JvVMInitArgs* VM_ARGS)
> Initializes the Java runtime
>
> Did you call that?
>
> Did you do everything in 12.15.2, Example?
Well it seems you did not get a chance to look at the example I attached in
the first mail. However to make things short, this is the code I use:
try
{
// create the virtual machine
JvCreateJavaVM(NULL);
JvAttachCurrentThread(NULL, NULL);
cout << "created VM" << endl;
String *fileName = JvNewStringLatin1("My.extlibrary");
JvInitClass(&System::class$);
System::out->println(fileName);
LibraryTest * p_libraryTest = LibraryTest::makelibrary(fileName);
LibraryTest::printlibrary(p_libraryTest);
JvInitClass(&LibraryTest::class$);
Library * p_library = p_libraryTest->getlibrary();
cout << "p_library=" << hex << p_library << endl;
JvInitClass(&Library::class$);
EList * p_books = p_library->getBooks();
cout << "p_books=" << hex << p_books << endl;
JvDetachCurrentThread();
}
catch (Throwable *t)
{
System::err->println(JvNewStringLatin1("Unhandled Java exception:"));
t->printStackTrace();
}
> That's fine. But first, we will try the simple things, then the hard
> things.
I also get the correct output for the cout and the java println:
[exec] created VM
[exec] My.extlibrary
I even get the (lengthy and thus omitted) output from the call to the static
LibraryTest::printlibrary(p_libraryTest); call.
I get the exception when I call p_library->getBooks();
I also tried to move the JvInitClass(&Library::class$); call above the
p_libraryTest->getlibrary(); call, but the the p_libraryTest->getlibrary();
call fails with this exception.
[exec] Unhandled Java exception:
[exec] java.lang.LinkageError: unexpected exception during linking:
org.eclipse.emf.examples.extlibrary.Library
[exec] at java.lang.VMClassLoader.transformException(java.lang.Class,
java.lang.Throwable) (/usr/lib64/libgcj.so.6.0.0)
[exec] at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/usr/lib64/libgcj.so.6.0.0)
[exec] at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.6.0.0)
[exec] at .JvInitClass(java.lang.Class)
(/usr/include/c++/4.0.2/gcj/cni.h:31)
[exec] at .main
(/home/lothar/workspace/org.eclipse.emf.examples.library.edit/cpp/librarytest/main.cpp:103)
[exec] at .__libc_start_main (/lib64/tls/libc-2.3.5.so)
[exec] Caused by: java.lang.NullPointerException
[exec] at java.lang.VMClassLoader.resolveClass(java.lang.Class)
(/usr/lib64/libgcj.so.6.0.0)
[exec] ...4 more
So I am a kind of stuck here :-(
> Andrew.
Lothar
--
Lothar Werzinger Dipl.-Ing. Univ.
framework & platform architect
Tradescape Inc.
111 West St. John Street, Suite 200
San Jose, Ca 95113
email: lothar@tradescape.biz