由于工作关系,需要编译老版本的GCC(4.8)。但在Ubuntu18.04上遇到很多问题,其中最难解决的是如下问题:
/usr/lib/x86_64-linux-gnu/libicuuc.so.60: symbol __cxa_throw_bad_array_new_length version CXXABI_1.3.8 not defined in file libstdc++.so.6 with link time reference
经过一番摸索,终于找到问题的根源,并顺利解决。具体原因及方法如下:
1. 原因
编译libstdc++-v3时,会使用命令msgfmt。而msgfmt依赖libstdc++.so.6,但编译时,gcc的编译系统会把msgfmt的依赖指向其自身的libstdc++.so.6,而不是系统自带的libstdc++.so.6。
此时的libstdc++.so.6比较旧,导致与msgfmt版本不兼容,从而出现了上述错误。
2. 解决方法
网上有三种解决方法,
There are typically three plausible solutions:
1. Recompile the offending library with an older compiler.
2. Install a newever version of the C++ library.
3. Rebuild the C++ library from sources (with a new enough compiler).
但是都不太可行,因为我需要编译多个旧版本的GCC。所以想到了能否让GCC编译时不用自身的libstdc++.so.6,摸索之后,发现可行。
具体操作是使用--with-host-libstdcxx编译参数,该参数可指明GCC编译时要使用的libstdc++.so.6,例如:
--with-host-libstdcxx=/usr/lib/x86_64-l