This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
using CNI (call compiled java from c++)
- From: David Blasby <dblasby at gmail dot com>
- To: java at gcc dot gnu dot org
- Date: Sun, 6 Feb 2005 19:45:49 -0800
- Subject: using CNI (call compiled java from c++)
- Reply-to: David Blasby <dblasby at gmail dot com>
I'm trying to call a java library from C++. I've been having all
sorts of problems and I havent been able to find any help on the
internet (and the search method for this mailling list is down). I've
scoured the internet for hours trying to find help, but havent found
any.
I've managed to get gcj all up and running and compiling a complex
java library - and it all seems to work fine from me. Now I want to
call the library from my c++ program. This is where I'm having
problems.
I'm using Fedora:
$ gcj --version
gcj (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
I'm trying to do the simpliest thing possible. I've seen this on many
help pages, but it just segfaults for me:
$ more test2.cc
#pragma GCC java_exceptions
#include <java/lang/Integer.h>
#include <gcj/cni.h>
int main(int argc, char** argv)
{
java::lang::Integer *x = new java::lang::Integer( 234);
}
$ gcc -g test2.cc -lgcj ; ./a.out
Segmentation fault
(gdb) where
#0 0x06aaf1aa in _Jv_equalUtf8Consts () from /usr/lib/libgcj.so.5
#1 0x06ad0b05 in _Jv_GetMethodLocal () from /usr/lib/libgcj.so.5
#2 0x06ad27da in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#3 0x06c65c5d in _Jv_InitClass () from /usr/lib/libgcj.so.5
#4 0x06ba15ae in java::lang::reflect::Modifier::isAbstract () from
/usr/lib/libgcj.so.5
#5 0x06ad16d3 in _Jv_PrepareConstantTimeTables () from /usr/lib/libgcj.so.5
#6 0x06ad288a in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#7 0x06aafaae in _Jv_AllocPtrFreeObject () from /usr/lib/libgcj.so.5
#8 0x06ad7eb6 in _Jv_AllocString () from /usr/lib/libgcj.so.5
#9 0x06ad818c in _Jv_NewStringUtf8Const () from /usr/lib/libgcj.so.5
#10 0x06ad343c in _Jv_PrepareCompiledClass () from /usr/lib/libgcj.so.5
#11 0x06ad28aa in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#12 0x06c65c5d in _Jv_InitClass () from /usr/lib/libgcj.so.5
#13 0x06ba15ae in java::lang::reflect::Modifier::isAbstract () from
/usr/lib/libgcj.so.5
#14 0x06ad16d3 in _Jv_PrepareConstantTimeTables () from /usr/lib/libgcj.so.5
#15 0x06ad2791 in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#16 0x06ad2789 in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#17 0x06aafaae in _Jv_AllocPtrFreeObject () from /usr/lib/libgcj.so.5
#18 0x06ad7eb6 in _Jv_AllocString () from /usr/lib/libgcj.so.5
#19 0x06ad818c in _Jv_NewStringUtf8Const () from /usr/lib/libgcj.so.5
#20 0x06ad343c in _Jv_PrepareCompiledClass () from /usr/lib/libgcj.so.5
#21 0x06ad28aa in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#22 0x06aafaae in _Jv_AllocPtrFreeObject () from /usr/lib/libgcj.so.5
#23 0x06ad7eb6 in _Jv_AllocString () from /usr/lib/libgcj.so.5
#24 0x06ad818c in _Jv_NewStringUtf8Const () from /usr/lib/libgcj.so.5
#25 0x06ad343c in _Jv_PrepareCompiledClass () from /usr/lib/libgcj.so.5
#26 0x06ad28aa in java::lang::Class::initializeClass () from
/usr/lib/libgcj.so.5
#27 0x06aaf849 in _Jv_AllocObjectNoFinalizer () from /usr/lib/libgcj.so.5
#28 0x06aaf872 in _Jv_AllocObject () from /usr/lib/libgcj.so.5
#29 0x080485f8 in main (argc=1, argv=0xfee73194) at test.cc:12
What am I doing wrong and where can I find more documentation?
thanks for you help,
dave