How to install gcc-11 ?
So apt-get won't install the latest version and also neither will following the instructions on this website:
https://gcc.gnu.org/install/
I'm having trouble with the build and configuration sections. When I try installing it based on these instructions:
https://www.linuxfromscratch.org/blfs/view/svn/general/gcc.html
I get to the step where it is supposed to configure:
root@greg-Q525UAR:~/gcc/build# ../configure --prefix=/usr --disable-multilib --with-system-zlib --enable-languages=c,c++,d,fortran,go,objc,obj-c++ && make
checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether ln works... yes checking whether ln -s works... yes checking for a sed that does not truncate output... /usr/bin/sed checking for gawk... no checking for mawk... mawk checking for libatomic support... yes checking for libitm support... yes checking for libsanitizer support... yes checking for libvtv support... yes checking for libphobos support... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for gcc option to accept ISO C99... none needed checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking whether g++ accepts -static-libstdc++ -static-libgcc... yes checking for gnatbind... no checking for gnatmake... no checking whether compiler driver understands Ada... no checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2 checking for objdir... .libs checking for the correct version of gmp.h... yes checking for the correct version of mpfr.h... no configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations. Source code for these libraries can be found at their respective hosting sites as well as at https://gcc.gnu.org/pub/gcc/infrastructure/. See also http://gcc.gnu.org/install/prerequisites.html for additional info. If you obtained GMP, MPFR and/or MPC from a vendor distribution package, make sure that you have installed both the libraries and the header files. They may be located in separate packages.
The problem is I look for these packages and I can't find the packages I need to install online. I did what it suggested with:
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations."
The problem is even with that it still won't work. Same error every time.
You need development packages for https://gmplib.org/ and https://www.mpfr.org/ and http://www.multiprecision.org/mpc it seems
I fixed it.
I had to manually install all of the packages. I couldn't do it with just the link u/tristan957 gave.
Those were the right dependencies, but what really got it working was using aptitude to install the official Ubuntu dependencies and packages for everything.
Videos
sudo apt install build-essential manpages-dev software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-11 g++-11
Then use update-alternatives to set default gcc...
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 --slave /usr/bin/cpp cpp /usr/bin/cpp-9 && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-11 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-11 --slave /usr/bin/cpp cpp /usr/bin/cpp-11;
To sample check settings to see which gcc is default you can run the following, if they show correct resuslts then the rest are fine...
gcc --version;g++ --version;gcov --version;
To reconfigure to any previous gcc version...
sudo update-alternatives --config gcc
You can do this on any version of ubuntu,... enjoy!
Here are my 6 different gcc's living side by side with the default being gcc-11:
$ sudo update-alternatives --config gcc
There are 6 choices for the alternative gcc (providing /usr/bin/gcc).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/gcc-11 1010 auto mode
1 /usr/bin/gcc-10 1000 manual mode
2 /usr/bin/gcc-11 1010 manual mode
3 /usr/bin/gcc-5 40 manual mode
4 /usr/bin/gcc-7 700 manual mode
5 /usr/bin/gcc-8 800 manual mode
6 /usr/bin/gcc-9 900 manual mode
Press <enter> to keep the current choice[*], or type selection number:
On Ubuntu 20.04, I followed the instructions here:
- https://packages.ubuntu.com/hirsute/amd64/gcc-11-multilib/download
Which is to:
Update the listed mirrors by adding a line to your /etc/apt/sources.list like this:
sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'Choose a mirror based on your location from the list. I chose the kernel mirror as I am in North America.
sudo apt-get updatesudo apt-get install gcc-11
After that which gcc-11 should produce a path to gcc-11. On my machine it was:
which gcc-11
produces: /usr/bin/gcc-11
I am not extremely adept in all things linux nor gcc, but after doing an apt search gcc-11 I get nothing, After doing an apt search gcc I do not see anything that shows an 11 version AFAICT, and when I try and follow what this link says it doesn't work because it doesn't find the package.
Thanks
Just add a flag and compile it using
g++ -std=c++11 1.cpp
Explanation:
-std=
โโโ Determine the language standard. This option is currently only supported when compiling C or C++.c++11
c++0x
โโโ The 2011 ISO C++ standard plus amendments. The name c++0x is deprecated.
You compile it with g++ -std=c++11 or g++ -std=gnu++11 to tell the compiler that you want that standard. This is shown in the error message you have.
As others have suggested, you need to enter the std commandline option. Let us make it easy for you
- Open terminal by pressing Ctrl+Alt+T
sudo gedit ~/.bashrcEnter the following line as the last line
alias g++="g++ --std=c++0x"- Save and close the file and close the terminal.
- Now open terminal again and compile your c++ 11 programs simply by
g++ filename.cpp
Thats it. By default it will compile for c++11 standard.
NOTE: If you follow the above mentioned option, to compile non-c++ 11 programs, you have to use
g++ --std=c++98 filename.cpp
gcc 4.6.3 supports many c++11 features. However, they are disabled by default. To enable them, use the following flag:
g++ -std=c++0x ...
This flag also disables GNU extensions; to keep them enabled, use -std=gnu++0x flag.
I've only recently switched to using Unix, so I apologize for the perhaps basic question.
I currently have gcc 9.3. As I like to keep up with the latest developments in the C++ standard, I'm interested in upgrading it to the latest version, which 11.1. However, I'm worried that doing so will break installed libraries which were compiled with 9.3, for example boost, or even cause incompatibilities within other Ubuntu packages.
Is this something that can be avoided? Will I need to reinstall all packages that depend on gcc manually if I upgrade it? Are there any other things I should be mindful of when upgrading gcc?
I accidentally installed 12.0.1 (experimental). How should I remove it from the system and then install GCC 12.1??
Hello, CUDA developers!I've been facing some challenges with compiling my CUDA project that utilizes OpenCV.
My development environment consists of CUDA 11.5, GCC 9, and Ubuntu 22.04 LTS, VSCode IDE. I'm getting a series of errors related to the C++ standard library when trying to compile my .cu file which uses C++17 features(also tried using GCC 9 with update-alternatives), OpenCV: Compiled with CUDA support. The specific errors start with issues in the <tuple> header and similar messages from other standard library headers, like <array> and <functional>, indicating something like "argument list for class template is missing".
I've tried the following:Ensuring GCC 11/9 is set as the default compilerUpdating the CUDA Toolkit to the latest version Simplifying my Makefile and ensuring proper flag orderingIsolating CUDA code from C++ standard library codeHowever, I'm still stuck with the errors during compilation, and they all point towards compatibility issues between NVCC and the GCC standard library headers.
I would really appreciate any advice on resolving these compilation errors. Have any of you encountered something similar or have insights that might assist me?
Hereโs the Makefile snippet for reference:
NVCCFLAGS=-ccbin g++-9 -I/usr/local/include/opencv4 -Xcompiler "-std=c++17" LDFLAGS=-lcudart -L/usr/local/lib $(shell pkg-config --libs opencv4)
And the compilation command that's causing the issue:
nvcc imageprocessing.cu -o ocr_app $(NVCCFLAGS) $(LDFLAGS)
Thank you in advance for your time and help!
[SOLVED]
Preferably not as separate packages but as newer versions of the existing ones, so that I wouldnโt have to do the update-alternatives magic.
As I side note, why doesnโt Ubuntu have this by default? A compiler is basically a text processing tool, it doesnโt really depend on anything that changes between Ubuntu versions, so you could have the same repository for all of them, without any version freezing.
Upd: Solution:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
version=$(apt-cache pkgnames | sed -nr 's/^gcc-(([0-9]+\.?)+)$/\1/p' \
| sort -n | tail -n1)
echo "The latest available GCC version: $version"
sudo apt-get install gcc-$version g++-$version
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$version 60 \
--slave /usr/bin/g++ g++ /usr/bin/g++-$version