1
我在Hp-ux上使用swig 2.0.7來包裝我們的C++庫。在發生崩潰時嘗試運行時沒有錯誤。在HP-UX上使用Swig時出現Java故障
使用:
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)
的痛飲命令
swig -c++ -package com.mybuild -java -I../Library -I../../Common mybuild.i
的痛飲接口文件
/* File : mybuild.i */
%module mybuild
%include "std_string.i"
%{
#include "mybuild.h"
%}
%include "mybuild.h"
在建築,我看到一個警告
warning #2177-D: function
"SWIG_JavaThrowException" was declared but never referenced
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
當我運行出現
故障,發生崩潰,我得到
(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.
用gdb,我收到了一點信息:
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
我的理論是,我需要調整痛飲停止這次崩潰。將不勝感激。
添加編輯代碼 對不起,我花了一段時間來解決可能導致問題的原因。我發現,這會導致系統崩潰
#include <iostream>
#include <string>
using namespace std;
static const string rangeFieldString("RangeField");
int main()
{
cout << "I sure hope this works" << endl;
return 0;
}
但這不會
#include <iostream>
#include <string>
using namespace std;
static const char* rangeFieldString("RangeField");
int main()
{
cout << "I sure hope this works" << endl;
return 0;
}
它在swig外工作嗎?我們可以通過一個最小的完整示例來看看你在包裝什麼功能,而不必猜測。 – Flexo
對不起,Flexo,我已經添加了一個什麼(我認爲)是問題的示例,具體來說,使用靜態const char *和靜態常量字符串 – user823848