undefined symbol: __gxx_personality_v0解决办法(转载)

“Java Native Interface Programmer's Guide and Specification”一书的第九章提供了一个Java调用C的通用框架,但是没有提供linux的实现,只支持windows和solaris。 在将该框架移植到linux以后,编译顺利通过。可是在运行时却发生了如标题所示的异常。

?

__gxx_personality_v0 is part of the G++ exception handling model defined
by the new C++ ABI in GCC.? The symbol is provided by the libstdc++
library, which is added to the link line by g++.? If you have a C++
routine using exceptions and link with Java, libstdc++.so may not be
referenced and the C++ support routines not found.??

You can inform the compiler that Java exceptions are to be used in a
translation unit, irrespective of what it might think, by writing
`#pragma GCC java_exceptions' at the head of the file.? This `#pragma'
must appear before any functions that throw or catch exceptions, or run
destructors when exceptions are thrown through them.

?

根 据网上的说法,这个问题产生的原因是java和c++的异常模型不一致,导致没有链接libstdc++.so。可是我加了'#pragma GCC java_exceptions'以后还是不行。这是什么原因呢?弄了半天,原来是我在编译时的命令有误。我用gcc编译和链接c++文件,结果就没有自 动链接上c++的标准库。把命令改为g++问题就迎刃而解了。此外我还发现了一个偏门的解决办法,就是编译和链接的时候还是用gcc命令,但是链接的时候 加上-lstdc++就行了。




发现不懂的东西还太多。这是让我一位牛人同志帮我搞定这个问题。很感谢他,但是遗憾的是自己没有能一步步研究出来。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值