Factsheet
How important are gcc versions?
c++ - How to Check the Version of my gcc? - Stack Overflow
what is the difference between the various versions of gcc? - Stack Overflow
How do I know what versions are supported by a compiler?
Videos
I have started getting unto assembly and optimising code and I was wandering how important if at all is it to upgrade the computer I am using.
Currently I am on gcc 11.4 which feels fairly old at this point when I am looking at what's out there.
Are the differences between versions thst big or is it generally fairly unimportant
The symlink to the 4.8.2 directory is nothing to worry about, it's normal for the libstdc++ headers on Red Hat Enterprise Linux (and therefore CentOS) to be arranged like that.
gcc --version will tell you the version of the gcc executable in your path.
rpm -q libstdc++-devel will tell you the version of the package that owns the C++ standard library headers.
rpm -ql libstdc++-devel will list the files installed by that package, which will include the files under /usr/include/c++/4.8.2
rpm --verify libstdc++-devel will check that you haven't messed up the C++ headers by replacing them with something else.
The error is more concerning, that implies you have messed something up. My guess would be it's in the from [...omitted by myself as it is irrelevant] part, which may actually be very relevant. std::locale should be declared in <bits/locale_classes.h> which is included before <bits/locale_facets_nonio.h>, so if it wasn't declared my guess is that you have some header that defines _LOCALE_CLASSES_H and prevents the standard library header from being read. Do not define include guards that start with underscores, they are reserved names.
I am not quite sure but below is more information
Stackoverflow: version of libc
Copy$ /lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.8.2.
Compiled on a Linux 3.13.9 system on 2014-04-12.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs>.
mandar@ubuntu:~/Desktop$
First erase the current update-alternatives setup for gcc and g++:
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
Install Packages
It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:
sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4
Install Alternatives
Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (Note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++
Configure Alternatives
The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Or switch using script:
#!/bin/sh
if [ -z "$1" ]; then
echo "usage: $0 version" 1>&2
exit 1
fi
if [ ! -f "/usr/bin/gcc-$1" ] || [ ! -f "/usr/bin/g++-$1" ]; then
echo "no such version gcc/g++ installed" 1>&2
exit 1
fi
update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
execute in terminal :
gcc -v
g++ -v
Okay, so that part is fairly simple. The tricky part is that when you issue the command GCC it is actually a sybolic link to which ever version of GCC you are using. What this means is we can create a symbolic link from GCC to whichever version of GCC we want.
- You can see the symbolic link :
ls -la /usr/bin | grep gcc-4.4 ls -la /usr/bin | grep g++-4.4
- So what we need to do is remove the GCC symlink and the G++ symlink and then recreate them linked to GCC 4.3 and G++ 4.3:
rm /usr/bin/gcc rm /usr/bin/g++ ln -s /usr/bin/gcc-4.3 /usr/bin/gcc ln -s /usr/bin/g++-4.3 /usr/bin/g++
- Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.3 and G++ 4.3:
ls -la /usr/bin/ | grep gcc ls -la /usr/bin/ | grep g++
- Finally we can check our GCC -v again and make sure we are using the correct version:
gcc -v g++ -v
That's my question. I'm running Linux which by default has g++ 11. I dunno if this is the latest g++ version or even what version of C++ it supports. How do I tell?
Just type
gcc --version
in any terminal near you.. ;-)
gcc -dumpversion
-dumpversionPrint the compiler version (for example,3.0) β and don't do anything else.
The same works for following compilers/aliases:
cc -dumpversion
g++ -dumpversion
clang -dumpversion
tcc -dumpversion
Be careful with automate parsing the GCC output:
- Output of
--versionmight be localized (e.g. to Russian, Chinese, etc.) - GCC might be built with option --with-gcc-major-version-only. And some distros (e.g. Fedora) are already using that
- GCC might be built with option --with-pkgversion. And
--versionoutput will contain something likeAndroid (5220042 based on r346389c) clang version 8.0.7(it's real version string)
First of all try to find a Ubuntu release that was out after the release of the required version of GCC. You can find the release history of GCC on GCC Releases - GNU Project - Free Software Foundation (FSF) and that of Ubuntu on Ubuntu version history - Wikipedia.
GCC 6.3 was released on December 21, 2016 and the closest Ubuntu release was Ubuntu 17.04 (Zesty Zapus) which was released in April 2017. You can use the archives of Zesty to install that. But since Zesty reached end of life way back in January 2018, therefore, its archives have been moved to Old Releases. To install GCC 6.3 from its repository:
Add the repository of Zesty and disable the Universe repository of Bionic since it contains 6.4 as well as 6.5 which might get installed while trying to install 6.3.
echo "deb http://old-releases.ubuntu.com/ubuntu zesty main" | sudo tee /etc/apt/sources.list.d/zesty.list sudo apt-add-repository -r universeUpdate the available package information and install GCC 6.3.
sudo apt update sudo apt install gcc-6Add GCC 6 as an alternative for GCC.
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 1Check the GCC version using
gcc -v. You should get the output like:Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2)
Once you're done with "making", you can remove the installed GCC 6.3 and the repository information of Zesty. And re-enable Universe repository of Bionic.
sudo apt purge gcc-6 sudo apt autoremove --purge sudo rm /etc/apt/sources.list.d/zesty.list sudo apt-add-repository universeFix the symlink for
/usr/bin/gcc.ln -sf /usr/bin/gcc-7 /usr/bin/gcc
Compile from source
Here I am maintaining a list of all trusted GCC packages for Ubuntu: How do I use the latest GCC on Ubuntu?
If your GCC of interest is not there, I don't see any option besides compiling your GCC from source (or better, port your software).
The easiest way is to check if crosstool-NG supports it that version. Here I've given an example: https://stackoverflow.com/questions/10412684/how-to-compile-my-own-glibc-c-standard-library-from-source-and-use-it/52454710#52454710
If not, you will just have to fight with manual build instructions found on Google e.g.: https://stackoverflow.com/questions/26305738/can-i-build-gcc-for-arm-with-an-x64-one/26306591#26306591