Converting std::__cxx11::string to std::string
up vote
61
down vote
favorite
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'
c++ string c++11 types std
|
show 4 more comments
up vote
61
down vote
favorite
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'
c++ string c++11 types std
1
The error sounds more like the compiler cannot find theinsertMember()
method.
– Matthäus Brandl
Oct 28 '15 at 15:22
1
Hm, it can find it with other programs I have that do not usec++11
– jorgen
Oct 28 '15 at 15:24
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
1
Additionally I guess you're using gcc. I would expect that there is sometypedef __cxx11::basic_string basic_string
somewhere instd
namespace of the string header. Do you compile the compilation unit containingH5::CompType
as well?
– Matthäus Brandl
Oct 28 '15 at 15:28
3
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38
|
show 4 more comments
up vote
61
down vote
favorite
up vote
61
down vote
favorite
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'
c++ string c++11 types std
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'
c++ string c++11 types std
c++ string c++11 types std
edited May 4 at 0:49
Baum mit Augen
39.9k12113146
39.9k12113146
asked Oct 28 '15 at 15:19
jorgen
1,11321225
1,11321225
1
The error sounds more like the compiler cannot find theinsertMember()
method.
– Matthäus Brandl
Oct 28 '15 at 15:22
1
Hm, it can find it with other programs I have that do not usec++11
– jorgen
Oct 28 '15 at 15:24
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
1
Additionally I guess you're using gcc. I would expect that there is sometypedef __cxx11::basic_string basic_string
somewhere instd
namespace of the string header. Do you compile the compilation unit containingH5::CompType
as well?
– Matthäus Brandl
Oct 28 '15 at 15:28
3
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38
|
show 4 more comments
1
The error sounds more like the compiler cannot find theinsertMember()
method.
– Matthäus Brandl
Oct 28 '15 at 15:22
1
Hm, it can find it with other programs I have that do not usec++11
– jorgen
Oct 28 '15 at 15:24
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
1
Additionally I guess you're using gcc. I would expect that there is sometypedef __cxx11::basic_string basic_string
somewhere instd
namespace of the string header. Do you compile the compilation unit containingH5::CompType
as well?
– Matthäus Brandl
Oct 28 '15 at 15:28
3
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38
1
1
The error sounds more like the compiler cannot find the
insertMember()
method.– Matthäus Brandl
Oct 28 '15 at 15:22
The error sounds more like the compiler cannot find the
insertMember()
method.– Matthäus Brandl
Oct 28 '15 at 15:22
1
1
Hm, it can find it with other programs I have that do not use
c++11
– jorgen
Oct 28 '15 at 15:24
Hm, it can find it with other programs I have that do not use
c++11
– jorgen
Oct 28 '15 at 15:24
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
1
1
Additionally I guess you're using gcc. I would expect that there is some
typedef __cxx11::basic_string basic_string
somewhere in std
namespace of the string header. Do you compile the compilation unit containing H5::CompType
as well?– Matthäus Brandl
Oct 28 '15 at 15:28
Additionally I guess you're using gcc. I would expect that there is some
typedef __cxx11::basic_string basic_string
somewhere in std
namespace of the string header. Do you compile the compilation unit containing H5::CompType
as well?– Matthäus Brandl
Oct 28 '15 at 15:28
3
3
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38
|
show 4 more comments
4 Answers
4
active
oldest
votes
up vote
80
down vote
accepted
Is it possible that you are using 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.
Source: GCC 5 Release Notes/Dual ABI
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwingundefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)
– Shravan40
Oct 25 '16 at 5:44
add a comment |
up vote
41
down vote
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If you can't do so, add to your project's makefile compiler option
-D_GLIBCXX_USE_CXX11_ABI=0
The define
#define _GLIBCXX_USE_CXX11_ABI 0/1
is also good but you probably need to add it to all your files while compiler option do it for all files at once.
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
add a comment |
up vote
0
down vote
I got this, the only way I found to fix this was to update all of mingw-64 (I did this using pacman on msys2 for your information).
add a comment |
up vote
0
down vote
For me -D_GLIBCXX_USE_CXX11_ABI=0 didn't help.
It works after I linked to C++ libs version instead of gnustl.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
80
down vote
accepted
Is it possible that you are using 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.
Source: GCC 5 Release Notes/Dual ABI
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwingundefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)
– Shravan40
Oct 25 '16 at 5:44
add a comment |
up vote
80
down vote
accepted
Is it possible that you are using 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.
Source: GCC 5 Release Notes/Dual ABI
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwingundefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)
– Shravan40
Oct 25 '16 at 5:44
add a comment |
up vote
80
down vote
accepted
up vote
80
down vote
accepted
Is it possible that you are using 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.
Source: GCC 5 Release Notes/Dual ABI
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
Is it possible that you are using 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.
Source: GCC 5 Release Notes/Dual ABI
Defining the following macro before including any standard library headers should fix your problem: #define _GLIBCXX_USE_CXX11_ABI 0
edited Oct 28 '15 at 15:52
answered Oct 28 '15 at 15:44
Matthäus Brandl
1,4961324
1,4961324
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwingundefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)
– Shravan40
Oct 25 '16 at 5:44
add a comment |
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwingundefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)
– Shravan40
Oct 25 '16 at 5:44
2
2
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
I tried this; now I get linker errors everywhere I use c++11 functions. Maybe there's no way to get this working with both c++11 and the compiled hdf5 library.
– jorgen
Oct 28 '15 at 16:06
1
1
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
For me, on Ubuntu 14.04, g++ 6.2 compiles by default with this set to 0, while on 16.04, the same g++ version compiles with it set to 1. On 14.04, setting this to 1 doesn't seem to actually do anything; the resulting object file isn't using the CXX11 ABI. I suspect this is a system limitation.
– Devin Lane
Sep 29 '16 at 7:50
I wasn't sure why compiler throwing
undefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)– Shravan40
Oct 25 '16 at 5:44
I wasn't sure why compiler throwing
undefined reference
and before searching for solution i checked my entire linkage in program and didn't find anything. After that i decided to search on web and found this. It works like charm, thanks :)– Shravan40
Oct 25 '16 at 5:44
add a comment |
up vote
41
down vote
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If you can't do so, add to your project's makefile compiler option
-D_GLIBCXX_USE_CXX11_ABI=0
The define
#define _GLIBCXX_USE_CXX11_ABI 0/1
is also good but you probably need to add it to all your files while compiler option do it for all files at once.
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
add a comment |
up vote
41
down vote
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If you can't do so, add to your project's makefile compiler option
-D_GLIBCXX_USE_CXX11_ABI=0
The define
#define _GLIBCXX_USE_CXX11_ABI 0/1
is also good but you probably need to add it to all your files while compiler option do it for all files at once.
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
add a comment |
up vote
41
down vote
up vote
41
down vote
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If you can't do so, add to your project's makefile compiler option
-D_GLIBCXX_USE_CXX11_ABI=0
The define
#define _GLIBCXX_USE_CXX11_ABI 0/1
is also good but you probably need to add it to all your files while compiler option do it for all files at once.
If you can recompile all incompatible libs you use, do it with compiler option
-D_GLIBCXX_USE_CXX11_ABI=1
and then rebuild your project. If you can't do so, add to your project's makefile compiler option
-D_GLIBCXX_USE_CXX11_ABI=0
The define
#define _GLIBCXX_USE_CXX11_ABI 0/1
is also good but you probably need to add it to all your files while compiler option do it for all files at once.
answered May 27 '16 at 8:12
Denis Sirotkin
41142
41142
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
add a comment |
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
1
1
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Compiler flag worked for me. thanks. I wasted 4 days for this stupid change in gcc!
– ray pixar
Aug 14 '16 at 5:52
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
Thanks. This flag also worked for me
– hbobenicio
Dec 14 '16 at 14:29
add a comment |
up vote
0
down vote
I got this, the only way I found to fix this was to update all of mingw-64 (I did this using pacman on msys2 for your information).
add a comment |
up vote
0
down vote
I got this, the only way I found to fix this was to update all of mingw-64 (I did this using pacman on msys2 for your information).
add a comment |
up vote
0
down vote
up vote
0
down vote
I got this, the only way I found to fix this was to update all of mingw-64 (I did this using pacman on msys2 for your information).
I got this, the only way I found to fix this was to update all of mingw-64 (I did this using pacman on msys2 for your information).
answered Jun 28 '17 at 21:18
ceorron
3961925
3961925
add a comment |
add a comment |
up vote
0
down vote
For me -D_GLIBCXX_USE_CXX11_ABI=0 didn't help.
It works after I linked to C++ libs version instead of gnustl.
add a comment |
up vote
0
down vote
For me -D_GLIBCXX_USE_CXX11_ABI=0 didn't help.
It works after I linked to C++ libs version instead of gnustl.
add a comment |
up vote
0
down vote
up vote
0
down vote
For me -D_GLIBCXX_USE_CXX11_ABI=0 didn't help.
It works after I linked to C++ libs version instead of gnustl.
For me -D_GLIBCXX_USE_CXX11_ABI=0 didn't help.
It works after I linked to C++ libs version instead of gnustl.
answered May 24 at 11:09
dimon4eg
548513
548513
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33394934%2fconverting-std-cxx11string-to-stdstring%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The error sounds more like the compiler cannot find the
insertMember()
method.– Matthäus Brandl
Oct 28 '15 at 15:22
1
Hm, it can find it with other programs I have that do not use
c++11
– jorgen
Oct 28 '15 at 15:24
Actually it seems to be the linker, not the compiler. What does "find" mean, what are those "other programs"?
– Matthäus Brandl
Oct 28 '15 at 15:25
1
Additionally I guess you're using gcc. I would expect that there is some
typedef __cxx11::basic_string basic_string
somewhere instd
namespace of the string header. Do you compile the compilation unit containingH5::CompType
as well?– Matthäus Brandl
Oct 28 '15 at 15:28
3
"I use c++11, but also some libraries that are not configured for it". This situation is problematic and you cannot really expect stuff to work. gcc.gnu.org/wiki/Cxx11AbiCompatibility web.archive.org/web/20170210052503/http://… and so on.
– n.m.
Oct 28 '15 at 15:38