0

I have tried to install a package on ubuntu that needs c++17 or newer libraries. I installed gcc-10 and g++-10. I also found that the default c++ library is c++14 by using this code:

man g++ | grep "This is the default for C++ code"

But I don't know how to change it to other versions. To run a simple code we can use -std=c++17. But I think Installing a package needs to change the default library.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458

1 Answers1

0

The c++ standard library traditionally is part of the compiler. On GNU/Linux systems typically GCC is used in conjunction with its standard library. An alternative would be CLang.

Note that the standard version is not only about the library, but even more so about language features that need to be implemented by the compiler directly.

Each compiler version has a default standards version, but supports several. The correct way to select a specific standards version during compilation is through a compiler flag. This should be part of a software's build system if the software depends on a specific version.

Compiler flags may be set in environmental variables, e.g. CXXFLAGS. These are then recognized by the popular build helpers like GNU Make or CMake. As the standards version to use is closely tied to the piece of software to be compiled, it would not be good practice to put the standards version into the environment.

But is it a problem if several pieces of software are built with a different standards version? No, not at all. Even when you link them together, the ABI compatibility is given across standards. See https://stackoverflow.com/a/49119902/21974 for a detailed answer on that topic.

Note that packages you install in Ubuntu are all pre-compiled, so you have no sway over how they are compiled.

ypnos
  • 50,202
  • 14
  • 95
  • 141