Calling a Java function from C++ using CNI

Shaun Jackman sjackman@telus.net
Tue Aug 10 05:42:00 GMT 2004


I have relentlessly trolled documentation and still have a persistent
SIGSEGV. I'd appreciate any help you can lend.

Welcome to HelloWorld. I'm sure you're all familiar with it:

[HelloWorld.java]
public class HelloWorld {

public static void
hello()
{
        System.out.println( "Hello, world!");
}

}
[EOF]

[hello.cc]
#include "HelloWorld.h"

int
main()
{
        HelloWorld::hello();
        return 0;
}
[EOF]

I generated HelloWorld.h using gcjh. I now run ./hello and SIGSEGV.
Here's some gdb output:

[clip]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1087308448 (LWP 4389)]
0x406f9c5a in _Jv_equalUtf8Consts () from /usr/lib/libgcj.so.5
(gdb) bt
#0  0x406f9c5a in _Jv_equalUtf8Consts () from /usr/lib/libgcj.so.5
#1  0x4071c1a5 in _Jv_GetMethodLocal () from /usr/lib/libgcj.so.5
#2  0x4071e015 in java::lang::Class::initializeClass ()
   from /usr/lib/libgcj.so.5
#3  0x408ccf98 in _Jv_InitClass () from /usr/lib/libgcj.so.5
#4  0x407f61cf in java::lang::reflect::Modifier::isAbstract ()
   from /usr/lib/libgcj.so.5
[clip]

What am I missing here? I suspect it's some allocation call in the C++
file. From what I've read though, calling Java static functions from
C++ does not require any explicit initialization. I'd be happy to
provide any further logs if I've been to relentless in my clipping.

Please cc me in your reply. Many thanks,
Shaun



More information about the Java mailing list