Something about g++, gcc
Introduction
GCC (GNU Compiler Collection) is a clollection of compilers for c, c++, and go etc. Usually we may confused about the compilers of c/c++ like Clang, MSVC and Intel C++.
Version of GCC
Up to now (2021/10/21), the newest version is 11.2. There are manuals for the latest full releases.
For Ubuntu bionic (18.04LTS) users, the GNU C compiler and Other Packages Related to gcc can be here. The version of gcc is 4.7, which does not support lots of program now. According to the Ubuntu, we can install gcc-4.8 at least and gcc-8 at most with sudo apt install.
In Ubuntu focal (20.04LTS), gcc-7,8,9,10 are works.
Generally, you can find the command gcc-${version} in your directory /usr/bin like this
➜ bin $ ls -l /usr/bin | grep gcc
-rwxr-xr-x 1 root root 428 5月 7 2006 c89-gcc
-rwxr-xr-x 1 root root 454 4月 11 2011 c99-gcc
lrwxrwxrwx 1 root root 5 10月 21 21:55 gcc -> gcc-8
lrwxrwxrwx 1 root root 22 12月 4 2019 gcc-7 -> x86_64-linux-gnu-gcc-7
lrwxrwxrwx 1 root root 22 3月 10 2020 gcc-8 -> x86_64-linux-gnu-gcc-8
lrwxrwxrwx 1 root root 8 5月 21 2019 gcc-ar -> gcc-ar-7
lrwxrwxrwx 1 root root 25 12月 4 2019 gcc-ar-7 -> x86_64-linux-gnu-gcc-ar-7
lrwxrwxrwx 1 root root 25 3月 10 2020 gcc-ar-8 -> x86_64-linux-gnu-gcc-ar-8
lrwxrwxrwx 1 root root 8 5月 21 2019 gcc-nm -> gcc-nm-7
lrwxrwxrwx 1 root root 25 12月 4 2019 gcc-nm-7 -> x86_64-linux-gnu-gcc-nm-7
lrwxrwxrwx 1 root root 25 3月 10 2020 gcc-nm-8 -> x86_64-linux-gnu-gcc-nm-8
lrwxrwxrwx 1 root root 12 5月 21 2019 gcc-ranlib -> gcc-ranlib-7
lrwxrwxrwx 1 root root 29 12月 4 2019 gcc-ranlib-7 -> x86_64-linux-gnu-gcc-ranlib-7
lrwxrwxrwx 1 root root 29 3月 10 2020 gcc-ranlib-8 -> x86_64-linux-gnu-gcc-ranlib-8
lrwxrwxrwx 1 root root 5 5月 21 2019 x86_64-linux-gnu-gcc -> gcc-7
-rwxr-xr-x 1 root root 1023K 12月 4 2019 x86_64-linux-gnu-gcc-7
-rwxr-xr-x 1 root root 1.1M 3月 10 2020 x86_64-linux-gnu-gcc-8
lrwxrwxrwx 1 root root 8 5月 21 2019 x86_64-linux-gnu-gcc-ar -> gcc-ar-7
-rwxr-xr-x 1 root root 31K 12月 4 2019 x86_64-linux-gnu-gcc-ar-7
-rwxr-xr-x 1 root root 27K 3月 10 2020 x86_64-linux-gnu-gcc-ar-8
lrwxrwxrwx 1 root root 8 5月 21 2019 x86_64-linux-gnu-gcc-nm -> gcc-nm-7
-rwxr-xr-x 1 root root 31K 12月 4 2019 x86_64-linux-gnu-gcc-nm-7
-rwxr-xr-x 1 root root 27K 3月 10 2020 x86_64-linux-gnu-gcc-nm-8
lrwxrwxrwx 1 root root 12 5月 21 2019 x86_64-linux-gnu-gcc-ranlib -> gcc-ranlib-7
-rwxr-xr-x 1 root root 31K 12月 4 2019 x86_64-linux-gnu-gcc-ranlib-7
-rwxr-xr-x 1 root root 27K 3月 10 2020 x86_64-linux-gnu-gcc-ranlib-8
Here I use gcc-8 as the main compiler and link to gcc. Users can select their perfrence as the main compiler.
For checking the search path when compiling C++, this command can work well. And ```gcc -print-prog-name=cc1` -v`` is work for C.
➜ bin $ `gcc -print-prog-name=cc1plus` -v
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/8
/usr/include/x86_64-linux-gnu/c++/8
/usr/include/c++/8/backward
/usr/lib/gcc/x86_64-linux-gnu/8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
/usr/include
End of search list.
Microsoft also explains the order of searching #include pathes.
C/C++ compiler support
C/C++ developed very fast in recent years and the standard updated frequently. Here presents compilers support for new C++ features.
For example, File system library (Defined in header <filesystem>, Defined in namespace std::filesystem) is a C++17 core language features and requries gcc-8. That is why I install the higher version gcc.
So please check the libraries that you used, version of compiler and standard of program language to make sure that they are working.