Home >Backend Development >C++ >How to Convert std::__cxx11::string to std::string in C 11?
In C , when using C 11 alongside libraries not configured for the standard, type conversion becomes necessary. Specifically, converting std::__cxx11::string to std::string is often required.
Problem Statement:
Previously, attempts to perform this conversion using constructs like (string) have failed, leading to linker errors similar to:
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'
Solution:
This issue may arise when using GCC 5 and attempting to link object files compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro. To resolve this, redefine the macro as follows:
#define _GLIBCXX_USE_CXX11_ABI 0
Place this definition before any inclusion of standard library headers in your code.
The above is the detailed content of How to Convert std::__cxx11::string to std::string in C 11?. For more information, please follow other related articles on the PHP Chinese website!