I am using swig 2.0.7 on Hp-ux to wrap our C++ libraries. There are no errors until attempting to run when a crash occurs.
Using:
HP-UX bob B.11.23 U ia64 0835920252 unlimited-user license
aCC: HP C/aC++ B3910B A.06.20 [May 13 2008]
java version "1.7.0.01"
Java(TM) SE Runtime Environment (build 1.7.0.01-jinteg_2012_05_10_04_39-b00)
Java HotSpot(TM) Server VM (build 22.1-b02-jre1.7.0.01-rc2, mixed mode)
the swig command is
swig -c++ -package com.mybuild -java -I../Library -I../../Common mybuild.i
the swig interface file
/* File : mybuild.i */
%module mybuild
%include "std_string.i"
%{
#include "mybuild.h"
%}
%include "mybuild.h"
On building, I see one warning
warning #2177-D: function
"SWIG_JavaThrowException" was declared but never referenced
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
Trouble occurs when I run, a crash occurs and I get
(0) 0xc0000000054f4f60 _ZN6Thread18trace_native_stackEv + 0x140 [/opt/java7/jre/lib/IA64W/server/libjvm.so]
(1) 0xc0000000055b10c0 _ZN7VMError14report_and_dieEv + 0x6c0 [/opt/java7/jre/lib/IA64W/server/libjvm.so]
(2) 0xc0000000050d85b0 _Z30_handle_uncaught_cxx_exceptionv + 0x50 [/opt/java7/jre/lib/IA64W/server/libjvm.so]
(3) 0xc0000000017390f0 _ZSt9terminatev + 0x50 [/usr/lib/hpux64/libCsup.so.1]
(4) 0xc000000001740090 __cxa_throw + 0x1b0 [/usr/lib/hpux64/libCsup.so.1]
(5) 0xc0000000015e3220 _ZNSs9_C_unlinkEv + 0x220 [/usr/lib/hpux64/libstd_v2.so.1]
(6) 0xc0000000015f08f0 _ZNSt5ctypeIcE12_C_initfacetERKSt6locale + 0x800 [/usr/lib/hpux64/libstd_v2.so.1]
(7) 0xc0000000015f3990 _ZNKSt6locale16_C_install_facetEPN4__rw15__rw_facet_baseERKNS_2idE + 0x1d0 [/usr/lib/hpux64/libstd_v2.so.1]
(8) 0xc0000000015f2ae0 _ZNKSt6locale13_C_make_facetERKNS_2idEbiPFPN4__rw15__rw_facet_baseEiPKcmE + 0x440 [/usr/lib/hpux64/libstd_v2.so.1]
(9) 0xc0000000016d5b60 _ZNSt8ios_base4InitC3Ev + 0x1c80 [/usr/lib/hpux64/libstd_v2.so.1]
(10) 0xc000000005e72f00 __sinit_optionset_cpp_ + 0x70 [/usr/testing/mybuild.so]
(11) 0xc00000000004e1a0 EM_mark_BOS + 0x50 [/usr/lib/hpux64/dld.so]
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (0xe0000000), pid=7231, tid=1
# Error: An uncaught C++ exception
#
# JRE version: 7.0
# Java VM: Java HotSpot(TM) 64-Bit Server VM (22.1-b02-jre1.7.0.01-rc2 mixed mode hp-ux-ia64 )
# Core dump written. Default location: /usr/testing/core or core.7231 (max size 2097151 kB). To ensure a full core dump, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /usr/testing/hs_err_pid7231.log
#
# Please report this error to HP customer support.
Using gdb, I received a little more info:
from /usr/lib/hpux64/libCsup.so.1
#16 0xc000000001740090:0 in __cxa_throw+0x1b0 ()
from /usr/lib/hpux64/libCsup.so.1
#17 0xc0000000015e3220:0 in std::string::_C_unlink()+0x220 ()
from /usr/lib/hpux64/libstd_v2.so.1
#18 0xc0000000015f08f0:0 in std::ctype<char>::_C_initfacet(std::locale const&)
+0x800 () from /usr/lib/hpux64/libstd_v2.so.1
#19 0xc0000000015f3990:0 in std::locale::_C_install_facet(__rw::__rw_facet_base*,std::locale::id const&) const+0x1d0 () from /usr/lib/hpux64/libstd_v2.so.1
#20 0xc0000000015f2ae0:0 in std::locale::_C_make_facet(std::locale::id const&,bool,int,__rw::__rw_facet_base* (*)(int,char const*,unsigned long)) const
---Type <return> to continue, or q <return> to quit---
+0x440 () from /usr/lib/hpux64/libstd_v2.so.1
#21 0xc0000000016d5b60:0 in std::ios_base::Init::Init()+0x1e40 ()
from /usr/lib/hpux64/libstd_v2.so.1
#22 0xc000000005e72f00:0 in __sinit_optionset_cpp_ ()
at /opt/aCC/include_std/iostream:48
#23 0xc00000000004e1a0:0 in EM_mark_BOS+0x50 () from /usr/lib/hpux64/dld.so
My theory is that I need to tweak Swig to stop this crash. Assistance would be appreciated.
Edit Code added Sorry about that, took me a while to zero in on what may be causing problem. I found that this will cause a crash
#include <iostream>
#include <string>
using namespace std;
static const string rangeFieldString("RangeField");
int main()
{
cout << "I sure hope this works" << endl;
return 0;
}
but this will not
#include <iostream>
#include <string>
using namespace std;
static const char* rangeFieldString("RangeField");
int main()
{
cout << "I sure hope this works" << endl;
return 0;
}
I found the solution to this. When building on the system, by adding -mt to CFLAGS and LDFLAGS, the problem was solved
CFLAGS=-Aa +e +DAportable +z +DD64 -mt
LDFLAGS=-Aa +e +DAportable -b +z +DD64 -mt