天天看点

undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>问题

问题现象:

手里有两台搭载不同版本的Ubuntu的编译器A和B,将在编译器A编译的开源库拷贝到编译器B上进行代码的编译,报标题的这样的错误;(为什么要在编译器A上编译用在B的库?因为A上有用到此开源库,且B上也会用到,索性就全部编译了)

undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>问题

问题原因:

查找原因,最大可能就是犹豫版本的问题导致,描述如下:

 gcc5以及以后的版本,将std::string和std::list重写,std::list变为std::__cxx11::list,std::string在c++03库是std::basic_string,而在c++11中变为了std::__cxx11::basic_string。而为了在编译的时候兼容旧版本(链接阶段),可在编译的时候启动_GLIBCXX_USE_CXX11_ABI 宏指定具体链接的库。

特意看了下编译器A和B的交叉编译器版本:

A

ubuntu0compile:~/hh/glog-master/_build$ arm-linux-gnueabihf-g++ --version
arm-linux-gnueabihf-g++ (Linaro GCC 4.9-2017.01) 4.9.4
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
           

B

root:~/code/tianhu_firmware/flexbuild/packages/apps/process$ arm-linux-gnueabihf-g++ --version
arm-linux-gnueabihf-g++ (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
           

可以看到A和B使用的版本确实不同;所以重新在B上编译开源库就可以了;遇到这样的错误大致可以归纳到犹豫版本间的兼容导致的;

参考:

https://www.cnblogs.com/lukybee/p/11846889.html

继续阅读