Sun Studio linking gcc libs: exceptions do not work

…衆ロ難τιáo~ 提交于 2019-11-29 10:52:36
antlersoft

Exception handling requires library and linker support which differs between Sun Studio C++ tool chain and Gnu C++ (In this way it is like name mangling, which you've already noted differs between the two tool chains). Using "C" linkage doesn't help you here, because the implementations of the functions you are linking to depend on that exception handling facility. You can't in general use C++ code built with two distinct tool chains within the same executable.

If you have to use Sun Studio because you are using closed-source libraries that are only compatible with Sun Studio, your easiest way forward is probably to get the library that "only builds with GNU C++" to build with the Sun C++ compiler, presuming that that library is open source. This might not be trivial and you might need to get support from the library's authors. I've done this when I had to by writing little scripts that look like GNU C++ commands that invoke the Sun compiler with the correct flags.

If that is out of the question, you might have to wrap the library you're trying to use in a service and use an RPC mechanism of some sort to access it from your Sun Studio compiled code.

Edit: Since the library linked to is specifically boost, this question might be helpful. In summary, some pieces of boost might build with your version of the Sun compiler.

It is not possible to load a shared library which is built with gcc into an executable built with solaris studio 12.3., if exceptions are not disabled.

The problem is that exceptions are not part of the C ABI. The Solaris Studio runtime and the gcc runtime use different implementations of _Unwind calls:

gcc (libstdc++ in particular) happens to use additional non-standard _Unwind calls which are not present in Solaris libc naturally, implementation details of Unwind implementation in libc differs to that of libgccs, so when all the standard _Unwind routines are resolved into Solaris version and one non-standard _Unwind routine is resolved into gcc version you get a problem (most likely that is what happens with you) (see here for more information)

It is not possible to execute one process which different C++ runtimes for the parts built with solaris studio and the gcc part. Therefore loading a shared library built with gcc into an executable built with Solaris Studio is not possible.


The good news is that from solaris studio 12.4 on, if you turn on C++11 support, it might actually work:

In Oracle Solaris Studio 12.4, the C++ compiler supports C++11, a new language and ABI (Application Binary Interface). In C++ 11 mode, the CC compiler uses the g++ ABI and a version of the g++ runtime library that is supplied with Oracle Solaris Studio. For this release, version 4.8.2 of the g++ runtime library is used. (reference)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!