类似这种:

解释一:

在CentOS系统上安装了gcc4.8.2和gcc7.2两个版本,gcc使用的是4.8.2版本,g++使用的是7.2版本,使用make编译cmake时出现c++11标准库未定义错误,两个版本的编译器使用的库版本也不同,对c++11标准的实现程度也不一样,所以会出现该问题,将g++换成4.8.2版本即解决该问题。
个人感觉编译器报标准库的错误很可能就是工具链版本的问题,修改使用合适的工具链应该即可,比如对gcc软件,所有编译器都使用统一版本即可。

————————————————
版权声明:本文为CSDN博主「璞小坤」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/walker_0_/article/details/83041846

解释二:

关于编译报错 error: cannot convert ‘const std::__cxx11::basic_string’ to ‘const char*’ 的处理

所以然

目前c++11标准开始普及,大家都开始默认支持或者使用c++11,例如GCC 5就开始默认启用C++11特性。但是由于c++11相对于c++03,很多实现的数据结构都发生了改变,所以两者并不能完全混用。
默认情况下,GCC 5在编译时会将std::string类型按c++11下std::__cxx11::basic_string 来处理,这时如果你调用的库在编译时未启用c++11特性则其中的std::string实际上是std::basic_string ,这时如果将c++11下的string当作参数传入非c++11的库时,就会出现error: cannot convert ‘const std::__cxx11::basic_string’ to ‘const char*’,或者未定义的方法引用(undefined reference)。

如果你是在GCC5下使用了非GCC5编译的库,或者编译时关闭了c++11特性的库,那么在编译你的代码时请相应的关闭C++11特性:

  • 0x01 编译选项中预定义宏
> -D_GLIBCXX_USE_CXX11_ABI=0

在cmakelists里面要怎么修改呢:

> add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
> 或者
> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")

还有如果用用cmake编译加参数要怎么修改呢:

> cmake -D_GLIBCXX_USE_CXX11_ABI=0 ../

后面的…/是你的CMakeLists相对于当前的路径

  • 0x02 代码中定义宏
> #define _GLIBCXX_USE_CXX11_ABI 0
  • 0x03 通过其他方法定义 _GLIBCXX_USE_CXX11_ABI 宏的值为0
    例如Qt中可以在Pro文件中添加:
> DEFINES += _GLIBCXX_USE_CXX11_ABI=0

————————————————
版权声明:本文为CSDN博主「ufolr」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ufolr/article/details/52669333

当然了少不了官方的说明:

添加链接描述

Dual ABI
In the GCC 5.1 release libstdc++ introduced a new library ABI that includes new implementations of std::string and std::list. These changes were necessary to conform to the 2011 C++ standard which forbids Copy-On-Write strings and requires lists to keep track of their size. (在GCC 5.1版本中,libstdc++引入了一个新的库ABI,它包括新的std::string和std::list实现。这些更改是必要的,以符合2011 C++标准,该标准禁止在写入字符串上复制,并要求列表跟踪其大小。
In order to maintain backwards compatibility for existing code linked to libstdc++ the library’s soname has not changed and the old implementations are still supported in parallel with the new ones. This is achieved by defining the new implementations in an inline namespace so they have different names for linkage purposes, e.g. the new version of std::list is actually defined as std::__cxx11::list. Because the symbols for the new implementations have different names the definitions for both versions can be present in the same library. (在GCC 5.1版本中,libstdc++引入了一个新的库ABI,它包括新的std::string和std::list实现。这些更改是必要的,以符合2011 C++标准,该标准禁止在写入字符串上复制,并要求列表跟踪其大小。
The _GLIBCXX_USE_CXX11_ABI macro (see Macros) controls whether the declarations in the library headers use the old or new ABI. So the decision of which ABI to use can be made separately for each source file being compiled. Using the default configuration options for GCC the default value of the macro is 1 which causes the new ABI to be active, so to use the old ABI you must explicitly define the macro to 0 before including any library headers. (Be aware that some GNU/Linux distributions configure GCC 5 differently so that the default value of the macro is 0 and users must define it to 1 to enable the new ABI.)
Although the changes were made for C++11 conformance, the choice of ABI to use is independent of the -std option used to compile your code, i.e. for a given GCC build the default value of the _GLIBCXX_USE_CXX11_ABI macro is the same for all dialects. This ensures that the -std does not change the ABI, so that it is straightforward to link C++03 and C++11 code together.
Because std::string is used extensively throughout the library a number of other types are also defined twice, including the stringstream classes and several facets used by std::locale. The standard facets which are always installed in a locale may be present twice, with both ABIs, to ensure that code like std::use_facet<std::time_get>(locale); will work correctly for both std::time_get and std::__cxx11::time_get (even if a user-defined facet that derives from one or other version of time_get is installed in the locale).
Although the standard exception types defined in use strings, most are not defined twice, so that a std::out_of_range exception thrown in one file can always be caught by a suitable handler in another file, even if the two files are compiled with different ABIs.
One exception type does change when using the new ABI, namely std::ios_base::failure. This is necessary because the 2011 standard changed its base class from std::exception to std::system_error, which causes its layout to change. Exceptions due to iostream errors are thrown by a function inside libstdc++.so, so whether the thrown exception uses the old std::ios_base::failure type or the new one depends on the ABI that was active when libstdc++.so was built, not the ABI active in the user code that is using iostreams. This means that for a given build of GCC the type thrown is fixed. In current releases the library throws a special type that can be caught by handlers for either the old or new type, but for GCC 7.1, 7.2 and 7.3 the library throws the new std::ios_base::failure type, and for GCC 5.x and 6.x the library throws the old type. Catch handlers of type std::ios_base::failure will only catch the exceptions if using a newer release, or if the handler is compiled with the same ABI as the type thrown by the library. Handlers for std::exception will always catch iostreams exceptions, because the old and new type both inherit from std::exception.

最后我的原因是:有个库用的gcc高版本编译的,所以给他换成我现在使用的低版本编译就好了。

【linuxs make 出现undefined reference to ‘std::__cxx11...】相关推荐

  1. undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_traits<char>, std::allocat

    linux升级后编译代码出现问题: undefined reference to `std::__cxx11::basic_ostringstream<char, std::char_trait ...

  2. gcc:undefined reference to 'std::cout'

    gcc says: undefined reference to 'std::cout' @ 10/17/2005 计算人生 boss让写的程序,要在linux跟windows下跑,结果我先用vs.n ...

  3. [ c++] cmake 编译时 undefined reference to `std::cout‘ 错误的解决方案

    [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案 参考文章: (1)[ c++] cmake 编译时 undefined refe ...

  4. gcc编译报错:undefined reference to `std::cout‘

    1 问题描述 下面的一段代码(代码来源)在使用gcc编译的时候报错:undefined reference tostd::cout'` 编译文件:test.cpp内容如下: #include < ...

  5. undefined reference to `std::ios_base::Init::Init() 解决

    undefined reference to `std::ios_base::Init::Init() 解决 (一)gcc 编译C++程序是提示错误undefined reference to `st ...

  6. Glib2: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)问题(六)

    报错:undefined reference to `std::__throw_out_of_range_fmt(char const*, ...) 解决: # emacs configure.acC ...

  7. gcc:undefined reference to ‘std::cout‘

    gcc:undefined reference to 'std::cout' gcc -o aa aa.cpp 出现错误: gcc:undefined reference to 'std::cout' ...

  8. undefined reference to `std::cout'等错误

    (1)gcc和g++都是GNU(组织)的一个编译器. (2)后缀名为.c的程序和.cpp的程序g++都会当成是c++的源程序来处理.而gcc不然,gcc会把.c的程序处理成c程序. (3)对于.cpp ...

  9. 【问题】 undefined reference to ‘std::thread::_State::~_State()@GLI)@GLIBCXX_3.4.22’ 类似问题解决

    问题现象: 引入了第三方的 Matlab 库,编译链接过程中出错,提示"xxx 未定义的引用" 问题原因: xxxx.so编译版本高于当前系统版本,gcc或g++版本较低导致 问题 ...

最新文章

  1. VDI序曲二十三 制作OFFICE 2003应用程序虚拟化序列
  2. SQL:EXISTS的用法理解(转)
  3. 扩增子图片解读7三元图:美的不要不要的,再多用也不过分
  4. select into mysql_MySQL select into 和 SQL select into
  5. 直播预告丨搭建高质量用户数据平台,加速车企数字化转型
  6. 来自web标准margin的嘲笑,你了解我吗?
  7. 基类指针和子类指针相互赋值
  8. 软件工程 speedsnail 第二次冲刺1次
  9. [C] 从文件读取数据
  10. android 著名播放器,十二大最著名的Android播放器开源项目
  11. vi编辑文件时如何批量替换字符串
  12. python批量修改文件夹名称,简洁快捷
  13. 打印出从1到1000的罗马数字
  14. 网络虚拟化中的 offload 技术:LSO/LRO、GSO/GRO、TSO/UFO、RSS、VXLAN
  15. javascript文字特效
  16. 交管123缴费显示代理服务器异常,交管12123服务异常怎么回事?交管12123网络请求失败怎么办...
  17. html引用css文件无效,关于html引用文件无效。
  18. 原著《西游记》中的几点不解和穿帮
  19. C++计算行列式(函数)
  20. 【ecshop---新增包邮卡功能】

热门文章

  1. mysql数据库安装:windows下安装MSI版
  2. linux中kvm配置文件,如何在linux中通过kvm安装虚拟机
  3. OPEN3D学习笔记(四)——Global registration
  4. 妹妹画的小恐龙和我用Python画的小恐龙,你更加喜欢谁的!❤️
  5. HTML5+CSS3网页设计从基础到入门——合并单元格
  6. 5G测试完毕,梦想能否照进现实
  7. 很短...道理很深---于丹
  8. 共享自助洗车小程序源码
  9. java基础学习(四)
  10. C++ decltype类型说明符