The problem you have is related to C++11 standard requiring a different implementation of C++ string (and list) type(s). For compatibility, g++5.2 and above compiles the new C++11 compliant type by default, (whether or not you specify -std=c++11), but you can set the macro
-D_GLIBCXX_USE_CXX11_ABI=0
to revert to the old C++ string type. New libstdc++ implementation contain both ABIs. So if you have binaries you have to link against with the old non-compliant ABI, you must set the macro above on your g++ compiles. This should produce binaries compatible with the old ABI.
Unfortunately if you are using libraries from the OS other than the C++ Standard Libraries, then unless these libraries are multi-arch in the sense of providing all functions which differ by ABI in both ABI's, then you're screwed because they'll probably only have the new ABI.
Having said that I have a problem on an old Ubuntu downloading an untrusted modern g++ which simply refuses to produce the new ABI. So it seems that backport from ppa:ubuntu-toolchain-r/test
is in fact badly broken because it refuses to produce binaries according to the new ABI.
Anyhow the bottom line is when you link together everything must either be the old ABI or the new ABI. The following will tell which you are using:
g++ --version
echo '#include <string>' > test.cpp
echo 'void f(std::string s) {}' >> test.cpp
cat test.cpp
g++ -std=gnu++11 -c -o test.o test.cpp
nm test.o | c++filt
If that has
std::basic_string<char, ....
in it, its the old ABI. If it has
std::__cxx11::basic_string<char, ...
in it, its the new ABI.
Run the following commands in sequence. I was getting same error. This worked for me.
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-snapshot
sudo apt-get install gcc-6 g++-6
Best Answer
You can install close to upstream version of GCC from Ubuntu Toolchain PPA: https://wiki.ubuntu.com/ToolChain#PPA_packages
Tested on Ubuntu 14.04.