c++ - 将 std::__cxx11::string 转换为 std::string

标签 c++ string c++11 types std

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

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

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 吗?

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 Release Notes/Dual ABI

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

关于c++ - 将 std::__cxx11::string 转换为 std::string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53404397/

相关文章:

c - 将十六进制字符串转换为十六进制字符数组的快速方法

php - 通过简化查询将字母拆分为组合 block

ios - 将 double 值插入 Swift 字符串

c++ - 尝试在声明中仅使用类名构造临时对象

c++ - 用一个 int 替换多个 bool 并使用位掩码的性能优势?

c++ - 在没有 c++11 的情况下删除 map 最后插入的元素的正确方法是什么?

c++11 - 融合改编的 std_tuple View ,转换为另一个元组

arrays - C++ : Is it normal to pass array reference to function

c++ - 类模板中没有扣除

c++ - 如何在解决方案资源管理器中保留源文件夹层次结构?