将 std::__cxx11::string 转换为 std::string

Converting std::__cxx11::string to std::string(将 std::__cxx11::string 转换为 std::string)
本文介绍了将 std::__cxx11::string 转换为 std::string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的是c++11,但也有一些库没有为它配置,需要一些类型转换.特别是我需要一种将 std::__cxx11::string 转换为常规 std::string 的方法,但是谷歌搜索我找不到这样做的方法并把前面的(string)不起作用.

I use c++11, but also some libraries that are not configured for it, and need some type conversion. In particular I need a way to convert std::__cxx11::string to regular std::string, but googling I can't find a way to do this and putting (string) in front does not work.

如果我不转换,我会收到这样的链接器错误:

If I do not convert I get linker errors like this:

undefined reference to `H5::CompType::insertMember(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, H5::DataType const&) const'

推荐答案

您是否可能使用 GCC 5?

Is it possible that you are using GCC 5?

如果您收到有关未定义引用符号的链接器错误,这些符号涉及 std::__cxx11 命名空间或标记 [abi:cxx11] 中的类型,那么这可能表明您正在尝试将使用不同值编译的目标文件链接在一起对于 _GLIBCXX_USE_CXX11_ABI 宏.当链接到使用旧版 GCC 编译的第三方库时,通常会发生这种情况.如果无法使用新 ABI 重建第三方库,则需要使用旧 ABI 重新编译代码.

If you get linker errors about undefined references to symbols that involve types in the std::__cxx11 namespace or the tag [abi:cxx11] then it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. This commonly happens when linking to a third-party library that was compiled with an older version of GCC. If the third-party library cannot be rebuilt with the new ABI then you will need to recompile your code with the old ABI.

来源:GCC 5 发行说明/双 ABI

定义以下宏之前包括任何标准库头应该可以解决您的问题:#define _GLIBCXX_USE_CXX11_ABI 0

Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0

这篇关于将 std::__cxx11::string 转换为 std::string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)