std::__cxx11::basic_string編譯錯誤解決方案

測試環境    CentOS Linux release 7.9.2009 (AltArch)   編譯環境gcc version 4.8.2 (GCC)

場景

        對接大華ARM架構的SDK,編譯鏈接libdhconfigsdk.so文件出錯:

/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_replace_aux(unsigned long, unsigned long, unsigned long, char)'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long)'
/dahua/lib/libdhconfigsdk.so: undefined reference to `__cxa_throw_bad_array_new_length'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(unsigned long, char, std::allocator<char> const&)'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned long) const'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() const'
/dahua/lib/libdhconfigsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::at(unsigned long)'
/dahua/lib/libdhnetsdk.so: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(unsigned long, char)'








解決過程

                1)更新gcc version 4.8.2 (GCC)支持C11,提示同樣錯誤

解決方案

            紅帽提供的開發工具包來管理gcc版本,這樣做的好處是隨時切換版本,並且可以並存多個版本,不破壞原有gcc環境。

紅帽官方Developer Toolset文檔地址:https://access.redhat.com/documentation/en-us/red_hat_developer_toolset/8/

devtoolset對應gcc的版本

devtoolset-3對應gcc4.x.x版本

devtoolset-4對應gcc5.x.x版本

devtoolset-6對應gcc6.x.x版本

devtoolset-7對應gcc7.x.x版本

安裝devtoolset包

yum install centos-release-scl yum install devtoolset-4

yum install centos-release-scl

yum install devtoolset-7

激活gcc版本,使其生效

scl enable devtoolset-7 bash

source /opt/rh/devtoolset-7/enable

此時通過gcc --version命令可以看到,gcc版本已經變成5.3.1,值得注意的是這僅僅在當前bash生效,如果需要永久生效,可以請自行添加環境變量。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章