Videos
gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:
- Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
- Step 2: make another build dir
Note this is important as running ./configure from within the source directory is not supported as documented here.
$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
- Step 3: installing GCC prequisites and run configure again
The missing libraries will be shown in above ./confgiure output, search and install them one by one.
$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
An alternative is to run the download_prerequisites script.
$ cd ../
$ cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
- Step 4: compile gcc-12
$ make -j16
Still flex is missing:
$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install
Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:
$ sudo apt install gcc-12
You can use Homebrew to install pre-built binaries. Follow instructions to install Homebrew at https://brew.sh/, then
brew install gcc for default GCC (currently 11) or brew install gcc@12 for gcc-12.
Note that it may compile missing dependencies.
Version no: Version 7.0.2 r154219 (Qt5.15.2)
How do I get VirtualBox to use gcc 12 instead of the default gcc which is 10 on Debian based when starting a virtual machine? I have compiled gcc-12 and is currently sitting in this directory ~/GCC-12.2.0/?
I have installed linux-xanmod, on linux it works fine but on linux-xanmod I get this error message:
The VirtualBox Linux kernel driver is either not loaded or not set up correctly. Please try setting it up again by executing '/sbin/vboxconfig'
I execute this /sbin/vboxconfig and get this output error msg:
vboxdrv.sh: Stopping VirtualBox services. vboxdrv.sh: Starting VirtualBox services. vboxdrv.sh: Building VirtualBox kernel modules. vboxdrv.sh: failed: Look at /var/log/vbox-setup.log to find out what went wrong. There were problems setting up VirtualBox. To re-start the set-up process, run /sbin/vboxconfig as root. If your system is using EFI Secure Boot you may need to sign the kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) before you can load them. Please see your Linux system's documentation for more information.
So I went into /var/log/vbox-setup.log and I see this:
Building the main VirtualBox module. Error building the module: make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/6.0.12-x64v1-xanmod1/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j8 modules make[1]: warning: -j8 forced in submake: resetting jobserver mode. warning: the compiler differs from the one used to build the kernel The kernel was built by: gcc-12 (Debian 12.2.0-9) 12.2.0 You are using: gcc (Debian 10.2.1-6) 10.2.1 20210110 make -f ./scripts/Makefile.build obj=/tmp/vbox.0 \ single-build= \ need-builtin=1 need-modorder=1
As it says I need to use gcc-12. So I have already compiled gcc-12 from source and it is in this directory ~/GCC-12.2.0/.
How do I get VirtualBox to use gcc from this directory ~/GCC-12.2.0/ instead of using the default installed gcc-10?