Step 1: improve the default g++ version from g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 to g++ (Ubuntu 9.4.0-1ubuntu1~18.04) 9.4.0
By default, Ubuntu 18.04 does not come with a version of GCC that supports the C++17 standard or later. However, you can install a newer version of GCC that does support C++17 by using a PPA (personal package archive) repository.
To install GCC 9 (which supports C++17) on Ubuntu 18.04, you can follow these steps:
- Add the PPA repository for GCC 9:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
- Update the package list:
sudo apt update
- Install GCC 9:
sudo apt install g++-9
- Make GCC 9 the default compiler:
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90
step 2: use g++ compile your c++ files
This will install GCC 9 and make it the default compiler on your system. You can then use it to compile C++ programs that include the
<filesystem>
header or other features from the C++17 standard.
To compile a C++ program that includes the<filesystem>
header, you can use the following command:
g++ -std=c++17 [options] file.cpp -o output
Where [options] are any additional options you want to use, file.cpp is the name of your C++ file, and output is the name of the output file you want to create. For example, to compile