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'
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
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.
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.
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 :)