Calling C++ with JNI on Sun. Program hangs.
I am calling a C++ library from Java using JNI.
The platform is SunOS 5.7 (SUNWspro compiler, Java j2sdk1_3_1)
The test JNI program works fine until I add a call to my custom C++ code.
When I declare one of the objects in the client library, the program hangs at the delaration. I have a print statement just before it in the C++ that works. It does not core dump or give any other error. I have tried various link variations using static and dynamic libraries all with the same result. Any ideas?
The client library is SunOS 5.0. I have tried the -compat5 compiler flag to no avail. I am pursuing getting the client library recompiled on this platform but if I am on the wrong tangent, please let me know.
-- Ken
[764 byte] By [
kbonacc] at [2007-9-26 1:13:56]

What version of the JDK are you using? Here is a discussion on Thread Stack Size that you might pursue, and see if it will solve your problem.
http://forum.java.sun.com/thread.jsp?forum=52&thread=145123
Good luck on this. I know how it feels trying to debug C code from java.
-Justin
For posterity, I tracked down the hang to the following line of code in the client library. Luckily the source was available:
// Convert the int to a string
int pCode;
strstream str;
str << pCode << ends;
// now use the int as a string ...
I changed it to the following using the standard C libs and the hang went away:
char str[11];
sprintf(str, "%d", pCode);
// now use the string ...
I read in other discussion items that there are conflicts with the Java VM and ostream libraries. Is this documented or is it just my link statement? I got the link below from another discussion thread but could find no better alternatives:
/opt/SUNWspro/bin/CC -G -Kpic -mt -o libMyLib.so myNative.o ExistingClientLibOrObj.o /lib/libsocket.a /lib/libnsl.a /opt/SUNWspro/SC5.0/lib/rw7/librwtool.a /opt/SUNWspro/SC5.0/lib/libCrun.a /opt/SUNWspro/SC5.0/lib/libiostream.a /opt/SUNWspro/SC5.0/lib/libCstd.a