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++就行了。

posted @ 2009-09-25 15:04  规格严格-功夫到家  阅读(10853)  评论(0编辑  收藏  举报