Convert std :: __ cxx11 :: string to std :: 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 a regular std::string , but googling. I cannot find a way to do this, and setting (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' 
+65
c ++ string casting types c ++ 11 std
Oct 28 '15 at 15:19
source share
6 answers

Is it possible that you are using GCC 5?

If you get linker errors about undefined character references that include types in the std :: __ cxx11 namespace or the [abi: cxx11] tag, then this probably indicates that you are trying to link together the object files that were compiled using different values ​​for the macro _GLIBCXX_USE_CXX11_ABI. This usually happens when connecting 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, you will need to recompile your code with the old ABI.

Source: GCC 5 / Dual ABI Release Notes

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

+87
Oct 28 '15 at 15:44
source share

If you can recompile all incompatible libraries that you use, do it with the compiler option

-D_GLIBCXX_USE_CXX11_ABI = 1

and then rebuild your project. If you cannot do this, add the makefile compiler to your project

-D_GLIBCXX_USE_CXX11_ABI = 0

Identify

#define _GLIBCXX_USE_CXX11_ABI 0/1

also good, but you probably need to add it to all your files, while the compiler option will do this for all files at once.

+47
May 27 '16 at 8:12
source share

The answers here are mainly focused on a short way to fix it, but if that doesn't work, I will take a few steps to check what worked for me (Linux only):

  • If linker errors occur when linking other libraries, create these libraries using debug symbols (GCC flag "-g")
  • List the characters in the library and type the characters that the linker complains about (enter the commands on the command line):

    nm lib_your_problem_library.a | grep functionNameLinkerComplainsAbout

  • If you get the method signature, go to the next step, if you have no symbols instead, you most likely deleted all the symbols from the library, and therefore the linker cannot find them when linking the library. Rebuild the library without removing ALL characters; if necessary, you can delete debugging characters (option strip -S ).

  • Use demangler c ++ to understand the method signature, like this one

  • Compare the signature of the method in the library that you just received with the signature that you use in the code (also check the header file), if they differ, use the correct header or the appropriate library or any other way that you now know to fix it
+1
Jul 03 '19 at 14:26
source share

When I had a similar problem, it was due to the fact that my library was compiled using clang++ , and it defaulted to libstdc++.so on my system. The application binary was compiled using clang and is associated with the -lc++ option.

The easiest way to check for dependencies is to run ldd libName.so

To fix this, you must use the same library in the application and library.

  • The easiest way. Build the library using clang++ and compile the application using clang++ . Without additional links to both steps. Standard stdlib will be used.

  • Create a library with -stdlib=c++ and compile the application with -lc++ . In this case, both the library and the application will use libc++.so

  • Build the library without additional options and link the binary with -lstdc++ . In this case, both the library and the application will use libstdc++.so

+1
Jul 30 '19 at 10:11
source share

I got this, the only way I decided to fix it was to update all mingw-64 (I did this using pacman on msys2 for your information).

0
Jun 28 '17 at 21:18
source share

For me, -D_GLIBCXX_USE_CXX11_ABI = 0 did not help.

It works after I contacted the C ++ libs version instead of gnustl.

0
May 24 '18 at 11:09
source share



All Articles