在 HP-UX 上使用 Swig 时 Java 崩溃

标签 java c++ swig acc

我在 Hp-ux 上使用 swig 2.0.7 来包装我们的 C++ 库。在发生崩溃时尝试运行之前没有错误。

使用:

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命令是

swig -c++ -package com.mybuild -java -I../Library -I../../Common mybuild.i 

swig接口(interface)文件

/* 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

我的理论是我需要调整 Swig 来阻止这次崩溃。将不胜感激。

添加编辑代码 对此感到抱歉,我花了一些时间才将可能导致问题的原因归零。我发现这会导致崩溃

#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;
}

最佳答案

我找到了解决这个问题的方法。在构建系统时,通过在CFLAGS和LDFLAGS中添加-mt,问题得到解决

CFLAGS=-Aa +e +DAportable +z +DD64 -mt
LDFLAGS=-Aa +e +DAportable -b +z +DD64 -mt

关于在 HP-UX 上使用 Swig 时 Java 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12311059/

相关文章:

java - 在 Java 中为泛型预定义乘法

java - 是什么破坏了我的 getResourceAsStream?

c++ - C++ 编译器中的奇怪行为 - 优化?

c++ - 为什么必须在何处以及为什么要放置"template"和"typename"关键字?

c++ - 在 perl 中调试由 SWIG 包装的共享库

python - 如何为 pytest 执行的 SWIG 编译的 C 代码生成代码覆盖率报告

python - 使用 SWIG 使用 3rd-Party 驱动程序构建 Python 模块

java - Jetty 似乎忽略了端口争论

java - 从接口(interface)访问单例的引用,可以吗?

c++ - 使用 mem_fun_ref() 传递用户定义的成员函数