This discussion is archived
1 Reply Latest reply: Jan 28, 2012 9:27 AM by jschellSomeoneStoleMyAlias RSS

Fatal error using C++ native library

lagarcia Newbie
Currently Being Moderated
Hi everyone,

I'm currently developing a JNI native library in C++ in order to use an original library from a third vendor. I'm trying to perform a very simple operation, just calling a concrete method from the original library from a Java sample application.

The same test in C++ is working fine, so I assume the vendor library is working correctly. But if I perform exactly the same code from within my native library using JNI, it give a crash like this:

# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000371c880580, pid=17095, tid=1077307712
#
# JRE version: 6.0_27-b07
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.2-b06 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libc.so.6+0x80580] wchar_t+0x0

I think this is telling me that there was an error in the native library, more concrete in the libc.so library which is part of the GNU C++ compiler used to generate the native library. I don't know what the "wchar_t" wants to mean, since I know that is a primitive type for wide chars. It might be that the error is related to the use of this primitive within the vendor library?

The compilation options that I'm using are the following:

...
#CCFLAGS = -shared -Wl,-soname,${TARGET} -lstdc++ -ldl -lpthread -fopenmp
CCFLAGS = -shared -Wl,-soname,${TARGET} -ldl -fopenmp
#FPFLAGS = -DLINUX -DGX_NAMESPACES -fPIC -fshort-wchar
#FPFLAGS = -fPIC -fshort-wchar
FPFLAGS = -fPIC
...
${TARGET} : FPEnginePulnixImpl.o
     ${CC} -o ${TARGET} FPEnginePulnixImpl.o ${CCFLAGS} -L${JAI_DIR} -lVrs

FPEnginePulnixImpl.o :
     ${CC} -o FPEnginePulnixImpl.o -I"${JDK_INCLUDES}" -I"${JDK_INCLUDES_LINUX}" -I"../jni/include" -I"${JAI_INCLUDES}" ${FPFLAGS} -c ../src/main/C++/FPEnginePulnixImpl.cc

I played around with those ones, without success so far. I debugged the native code and I know the crash is coming when I call a constructor of a C++ class of the vendor library. Is there something I could do about this? BTW, on Windows is working fine, but indeed, the vendor library is a different one. I've got the impression that there's something in the JNI wrapper of the JDK6 that I'm using that makes the vendor library to crash, either that or something wrong with the compilation of my native library.

Any help will be welcome.

Thanks and regards,
Luis
  • 1. Re: Fatal error using C++ native library
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    Most often errors are caused by
    1. Pointer errors
    2. Api misuse, such as using something in the wrong order (which actually leads to a pointer problem but it not really the cause.)

    Keep in mind that the fact that code runs 'ok' on one system is NOT a safe indicator that the above problems do not exist.

    If it is not that then if the binaries have incompatible build properties then that can cause problems.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points