This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCJ and C++ (calling Java from C++)


I cited the full mail, as this is a reply to the mailing list :-)

On Tuesday 29 November 2005 03:16, you wrote:
> Lothar Werzinger writes:
>  > Sorry to contact you directly, but I found references on the WEB
>  > (ftp://gcc.gnu.org/pub/gcc/summit/2004/GCJ New ABI.pdf) that lead me to
>  > believe you might be the right people to ask my question.
>  >
>  > I would like to use an ecore EMF model in my C++ application. As a test
>  > I used the library example from Eclipse EMF. I added a Java class and a
>  > C++ main to test it. (Both are in the
>  > org.eclipse.emf.examples.library.edit directory). I also provide a
>  > build.xml ANT script to build and run the test. I attached the example
>  > files
>  >
>  > Currently the C++ main can successfully execute a static Method. It even
>  > can execute a static Method that returns a Java object. But as soon as I
>  > try to invoke a Method on that returned object I get an exception:
>  >
>  >      [exec] Unhandled Java exception:
>  >      [exec] java.lang.NullPointerException
>  >      [exec] at .main
>  > (/home/lothar/workspace/org.eclipse.emf.examples.library.edit/cpp/librar
>  >ytest/main.cpp:99) [exec] at .__libc_start_main
>  > (/lib64/tls/libc-2.3.5.so)
>  >
>  > Is that related to the writing in the GCJ Manual that
>  > "-findirect-dispatch: CNI also does not yet work with the binary
>  > compatibility ABI"?
>  >
>  > Is there a way to make my program work? It would be a big win if I could
>  > use the EMF ecore model in my C++ application.
>  >
>  > Is there a newer GCJ than the one I use that may fix this problem?
>  >
>  > Thanks in advance if you can respond to my mail.
>  >
>  > P.S.
>  > gcj --version
>  > gcj (GCC) 4.0.2 20050901 (prerelease) (SUSE Linux)
>  > Copyright (C) 2005 Free Software Foundation, Inc.
>  > This is free software; see the source for copying conditions.  There is
>  > NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
>  > PURPOSE.
>
> Questions like this should probably be sent to java@gcc.gnu.org.

Thanks for the pointer. I apologize and hereby move the thread to 
java@gcc.gnu.org.

> Have you read Section 12.15, Invocation  ?

Well if this subtle hint means if I noticed the (rather non obvious) call to 
JvInitClass. I didn't noticed it the first time. Actually I copied/modified 
an example I found on the WEB
But in general I do read manuals :-)

However after if I added JvInitClass() calls to my main I still get an 
exception.
Is there anything else I overlooked? I do really not want to bother you, but 
if you know if this is a solvable problem (and how to solve it), please point 
me in the right direction.

My code now looks like this:
    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();     // this is line 107
    cout << "p_books=" << hex << p_books << endl;

and I now get 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:107)
     [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


>
> Andrew.

P.S.
If anybody on the list wants the example code, please contact me.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]