undefined reference to cxx11::basic_string

I am trying to run the code here:

https://github.com/PfAndrey/supermariohd/issues/1

When I try `cmake --build . --config Release`, I get all these `undefined reference to cxx11::basic_string` errors

My g++ version is 7.4.0 according to `g++ --version`

Can anyone help with this?
You should not update your system compiler so casually.

C++11 necessitated a change to GCCs implementation of the binary interface of a few standard library components. For compatibility reasons, the library soname was not changed.

Your old system compiler assumes the C++03 ABI. Your new compiler does not. You need to make sure all your code complies with the same binary interface.

Prefer to rebuild your libraries and code with the new ABI. If you cannot, define _GLIBCXX_USE_CXX11_ABI=0 and compile your new code against the old (nonconforming) ABI, then revert your compiler to the default.

See:
https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
You mean I should use the previous g++ version 5.0 or whatever? When I did that, I got all these errors like /usr/include/c++/5/bits/unordered_map.h:379:2: error: ‘value’ is not a member of `, so upgrading to g++ 7.4 resolved those errors, but produced the new errors I'm getting
You mean I should use the previous g++ version 5.0 or whatever?

The maintainer said that this project requires G++7, so you must use G++7 or later to compile this project.

The problem is that in general, code compiled by one compiler and one set of compiler settings is not compatible with code compiled by another compiler and set of compiler settings. We would say that in general, code compiled with different settings or with different compilers have differing application binary interfaces, or ABIs.

G++ tries to provide a forward-compatibility guarantee where there isn't one in general, but this time the guarantees couldn't be maintained.

You must build all of your code against the same ABI, preferably with the same compiler.
This might be as simple as saying
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake --build . clean
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake -DCMAKE_BUILD_TYPE=Release --build . 


If that doesn't work because of dependencies on third-party libraries built against the old ABI, you need to either rebuild the old libraries with the new compiler (maybe a big deal), or specifically ask for G++7 to emit ABI-compatible code by specifying _GLIBCXX_USE_CXX11_ABI=0 on the command line (easy):
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake -D_GLIBCXX_USE_CXX11_ABI=0 --build . clean
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake -D_GLIBCXX_USE_CXX11_ABI=0 \
  -DCMAKE_BUILD_TYPE=Release --build . 

Then you should probably revert your system compiler to the old one, I guess with update-alternatives if that's what you used. This particular change to the compiler settings (the default value of _GLIBCXX_USE_CXX11_ABI) is a breaking change. No need to uninstall G++7.

See this page for some background:
https://wiki.gentoo.org/wiki/Upgrading_GCC
This one is relevant to you too, despite the difference in the version numbers
https://wiki.gentoo.org/wiki/Upgrading_from_gcc-4.x_to_gcc-5.x
Last edited on
It's possible that updating to Ubuntu 18.04 would help.
Last edited on
I don't know if I'm doing this correctly. But I tried the following:

CC=gcc-7 CXX=/usr/bin/g++-7 cmake --build . clean

and got Unknown argument clean

CC=gcc-7 CXX=/usr/bin/g++-7 cmake -DCMAKE_BUILD_TYPE=Release --build . produced

1
2
3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Me/Desktop/supermariohd/build


CC=gcc-7 CXX=/usr/bin/g++-7 cmake -D_GLIBCXX_USE_CXX11_ABI=0 --build . clean produced

CMake Error: The source directory "/home/Me/Desktop/supermariohd/build/clean" does not exist.

CC=gcc-7 CXX=/usr/bin/g++-7 cmake -D_GLIBCXX_USE_CXX11_ABI=0 \ -DCMAKE_BUILD_TYPE=Release --build . produced

1
2
3
-- Configuring done
-- Generating done
-- Build files have been written to: /home/Me/Desktop/supermariohd/build


Seems like the above didn't work because I still don't see the binary `SuperMario` in my directory. Was I supposed to do something with update-alternatives?


Last edited on
Not your fault, I just got the syntax wrong, sorry. (I rarely use CMake.)

Try this:
$ cd /home/Me/Desktop/supermariohd
$ rm -fr build
$ mkdir build
$ cd build
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake -D_GLIBCXX_USE_CXX11_ABI=0 \ 
  -DCMAKE_BUILD_TYPE=Release .. 
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake --build .

No worries. Looks like it almost worked, until the end

The error I get with CC=gcc-7 CXX=/usr/bin/g++-7 cmake --build . is at: https://pastebin.com/LuBGgNXS
Last edited on
can anyone help with this?
Sorry I didn't respond sooner. I'm no longer confident in my ability to solve the problem remotely.

I think I still haven't shown the right way to use CMake, because the problem is still the same: the ABI is mismatched. In the narrow scope of the problem it doesn't matter which you use. If you can use one ABI, you can (probably) use the other.

I hoped that someone else would tell me where I am going wrong, but I have some ideas anyway:
1. Delete and recreate the build directory, then try building everything with the default settings:
$ CC=gcc-7 CXX=/usr/bin/g++-7 cmake

2. Delete and recreate the build directory, then try setting CMAKE_CXX_FLAGS (or is it CXXFLAGS?) through the environment instead of passing the option to cmake:
$ CMAKE_CXX_FLAGS=-D_GLIBCXX_USE_CXX11_ABI=1 CC=gcc-7 CXX=/usr/bin/g++-7 cmake
Or maybe
$ CC=gcc-7 CXX=/usr/bin/g++-7 -DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=1" cmake

3. Try editing CMakeLists.txt to directly include the line
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
Somewhere after the line
project(SuperMario VERSION 0.99 LANGUAGES C CXX)
Then rebuild.

FWIW, I was able to build this on my computer with no additional effort. I wish I could be more helpful.

Note: feel free to try systematically _GLIBCXX_USE_CXX11_ABI=0 and =1.
Last edited on
Just tried all your suggestions and none of them work
Topic archived. No new replies allowed.