Linux which version gcc

How to Know the GCC Version Used to Compile Linux kernel on Linux

This post will guide you how to know the gcc compiler version that used to compile the current linux kernel on CentOS/Ubuntu Linux system. How to find the Linux kernel version and GCC compiler version on your system. How to identify what version of GCC compiler was used to compile your running Linux kernel.

Check Linux Kernel Version

If you want to get the running Linux kernel version on your system, you can use the following command to get it.

From the above outputs, you can know the current version of running Linux kernel is 4.8.0-36.

Check GCC Compiler Version Used to Compile Kernel

If you installed multiple versions of GCC compilers in your system, and then you want to check the GCC compiler version that used to compile the running Linux kernel on your system, How to achieve the result. You can get it from /proc/version file. type the following command:

So we can see from the above outputs that the gcc version is gcc version 5.4.0 .

Install An Older GCC Compiler Version (gcc 4.3.2)

If you need to install an older version of GCC Compiler on your Linux system, you can download the GCC Compiler source package from http://mirrors-usa.go-parts.com/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.gz, and compile and install the source code. just do the following commands:

Check the Version of GCC Compiler Is Installed

If you want to check the versions of GCC compiler are installed in your Linux system, you can use the following commands:

For Ubuntu/Debian Linux:

For CentOS/RHEL Linux:

Choose the Default GCC Version

If you want to compile a C program with a specific version of GCC Compiler, then you need to change the default GCC compiler version, for example, you want to choose the GCC compiler 3.4 as the default compiler. just run one of the following command:

Verify the default GCC Compiler Version

Video: Check GCC Version Used to Compile running Linux kernel


See Also:

Источник

How to Check gcc Version on Ubuntu

Question :
How to check gcc version on my Ubuntu ?

Answer :

gcc – GNU project C and C++ compiler. There are a few options to obtain GCC version in Ubuntu.

Option 1
Issue command “gcc –version
Example :

Option 2
Issue command “gcc -v
Example :

Option 3
Issue command “aptitude show gcc
Example :

Question : How to check Ubuntu Version that you are running? Answer : To print…

Checking what version of Ubuntu you are running is very easy. From my own experience,…

Question : How to check gcc version ? What commands to check gcc version ?…

This short guides shows how to quickly check your postfix mail server version. Basically, postfix…

In this post, i will share the quick steps on how to check linux CentOS…

Источник

How to choose the default gcc and g++ version?

So I have installed gcc-4.4 and gcc-4.3 (same for g++). Now as far as I remember there is a tool in Ubuntu which sets the symlinks for you if you just tell it which version you want. However it does not seem to work in the newest version, which I find disappointing.

Читайте также:  Параметры установки устройств windows 10 как найти

7 Answers 7

First erase the current update-alternatives setup for gcc and 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:

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.)

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:

Or switch using script:

execute in terminal :

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 :
  • 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:
  • Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.3 and G++ 4.3:
  • Finally we can check our GCC -v again and make sure we are using the correct version:

Is this really desirable? There are ABI changes between gcc versions. Compiling something with one version (eg the entire operating system) and then compiling something else with another version, can cause conflict.

For example, kernel modules should always be compiled with the same version of gcc used to compile the kernel. With that in mind, if you manually altered the symlink between /usr/bin/gcc and the version used in your version of Ubuntu, future DKMS-built modules might use the wrong gcc version.

If you just want to build things with a different version of gcc , that’s easy enough, even with makescripts. For example, you can pass in the version of gcc in the CC environment variable:

You might not need it on the make command (configure scripts usually pull it in) but it doesn’t hurt.

Edit:

This assumes that you have installed the version first, with e.g.:

Original:

And here is a one-liner for those who are lazy, just change change the number at the end to the version you want. It will make the change for gcc and/or g++

In this example I switched to 4.9

There are no error checks and what not in this example, so you might want to check what will be run before you run it. Just add echo before sudo. For completeness I provide check line as well:

The output from the check should be something like:

Источник

How to check the C++ version is being used in Linux OS?

I have tried to print:

And Getting 1 as output.

Also I have tried: g++ -version command. It produces the output:

How to determine the version of the C++ standard with the above output ??

Or Is there any other way ??

Somewhere I found like, Boost.Config has a plethora of macros that can be used to test for support for specific C++11 features.

3 Answers 3

And Getting 1 as output

It sounds like __cplusplus is being coerced into a bool . You should probably show the full code, and not the abridged snippet.

Maybe you can cast __cplusplus to an unsigned type. Or maybe you need to include a c++ header like . However, I cannot reproduce your results when doing so:

How to determine the version with the above output ?? Or Is there any other way ??

Usually you ask the compiler to give them to you. Also see the output of echo ‘#include ‘ | g++ -x c++ -dM -E — | sort . The one below is from Fedora 25 with GCC 6.3.

You can get even more macros tuned for the particular CPU you have by adding -march=native . Then you will see preprocessor definitions like __AES__ , __PCLMUL__ , __SHA__ , etc.

You can also use different versions of the C++ standard with -std=c++03 , -std=c++11 , -std=c++14 , etc.

Читайте также:  Windows server bluetooth не поддерживается что делать

If you want specific features in c++, you can use the macros described here: e.g. you want to know if lib chrono is available: __cpp_lib_chrono contains a value 201510

The version of the used c++ standard can be checked by: __cplusplus . For c++17 the value is «201703», for c++14 it is «201402». But also if the compiler seems to have c++14 enabled, you should keep in mind that not all features must be present. For specific features you can check the macros above. This specific part of the question has already an answer here: How to determine the version of the C++ standard used by the compiler?

gcc for example have also predefined macros to check e.g. :__GNUC__

It is somewhat unclear if you want to check during compile time or before, like in configure step.

If you want to know something in configure step, you can write small test progs which test for the above described macros and write the result to stdout so you can check in gmake or autotools.

Also you can check things in Makefile and share that info with your compiler by defining macros with -D flag.

Источник

How To Compile And Run a C/C++ Code In Linux

I am a new Linux user and student who used to write C or C++ programs on MS-Windows. Now, I am using Ubuntu Linux. How can I compile a C or C++ program on Linux operating systems using bash Terminal application?

To compile a C or C++ program on any Linux distro such as Ubuntu, Red Hat, Fedora, Debian and other Linux distro you need to install:

Tutorial details
Difficulty level Easy
Root privileges No
Requirements GNU C/C++ compiler
Est. reading time 2 minutes
  1. GNU C and C++ compiler collection
  2. Development tools
  3. Development libraries
  4. IDE or text editor to write programs

If you are using Fedora, Red Hat, CentOS, or Scientific Linux, use the following yum command to install GNU c/c++ compiler:
# yum groupinstall ‘Development Tools’
If you are using Debian or Ubuntu Linux, type the following apt-get command to install GNU c/c++ compiler:
$ sudo apt-get update
$ sudo apt-get install build-essential manpages-dev

Step #2: Verify installation

Type the following command to display the version number and location of the compiler on Linux:
$ whereis gcc
$ which gcc
$ gcc —version
Sample outputs:

Fig. 01: GNU C/C++ compilers on Linux

How to Compile and Run C/C++ program on Linux

Create a file called demo.c using a text editor such as vi, emacs or joe:

How do I compile the program on Linux?

Use any one of the following syntax to compile the program called demo.c:

In this example, compile demo.c, enter:

If there is no error in your code or C program then the compiler will successfully create an executable file called demo in the current directory, otherwise you need fix the code. To verify this, type:
$ ls -l demo*

How do I run or execute the program called demo on Linux?

Simply type the the program name:
$ ./demo
OR
$ /path/to/demo
Samples session:

Animated gif 01: Compile and run C and C++ program demo

Compiling and running a simple C++ program

Create a program called demo2.C as follows:

To compile this program, enter:

To run this program, type:

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

How do I generate symbolic information for gdb and warning messages?

The syntax is as follows C compiler:
cc -g -Wall input.c -o executable
The syntax is as follows C++ compiler:
g++ -g -Wall input.C -o executable

How do I generate optimized code on a Linux machine?

The syntax is as follows C compiler:
cc -O input.c -o executable
The syntax is as follows C++ compiler:
g++ -O -Wall input.C -o executable

How do I compile a C program that uses math functions?

The syntax is as follows when need pass the -lm option with gcc to link with the math libraries:
cc myth1.c -o executable -lm

How do I compile a C++ program that uses Xlib graphics functions?

The syntax is as follows when need pass the -lX11 option with gcc to link with the Xlib libraries:
g++ fireworks.C -o executable -lX11

How do I compile a program with multiple source files?

The syntax is as follows if the source code is in several files (such as light.c, sky.c, fireworks.c):
cc light.c sky.c fireworks.c -o executable
C++ syntax is as follows if the source code is in several files:
g++ ac.C bc.C file3.C -o my-program-name
See gcc(1) Linux and Unix man page for more information.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

thank you so much ur solution gave a relief…
it made my gcc command to work

Very nice article…..

In Fig. 01, you did “whereis” twice. Shouldn’t it be “which” the second time? Thanks for the tut though. Big fan!

Another mistake, please change the following comment:
## assuming that executable-file-name.c exists ##
to
## assuming that program-source-code.c exists in the current directory ##

how to compile a program that use math functions and other things?

For the sake of supplying an example, let’s say you want to use the cosine function. This is supplied in the Linux math library. The cosine function is called ‘cos()’. Similarly, the sine function is called ‘sin()’.

First, to find information about how to use them, type “man cos” in a terminal session. This gives you the manual page for the cosine function. The output from ‘man’ may vary for your system, but it likely tells you three things: 1. first, include the math.h header, 2. cos() takes a ‘double’ as its argument and it returns a double as its output, 3. to build your program, tell the C compiler to include the math library (-lm).

Here’s a sample program that does all of this:

Love it!
Thank you. I have a trouble in doing step 1 and 2. But they are fixed.

thank u ,
need pdf of the commands guide to access the c/c++/java.

to compile and run a c++ program in ubuntu follow these simple steps:
1 open terminal window.
2 type “gedit” .
3 A gedit window will appear whereyou can write your program.
4 save your program as “filename.cpp” on desktop, “.cpp” is compulsory.
5 open terminal again and type “cd Desktop”.
6 In second line type “g++ filename.cpp”.
7 Type “./a.out”.
NOW YOUR WILL RUN.

very nice to your step.
thanks

Thanks! This article really helped me to find the GNU compiler in a Linux Operating System and showed me how to compile a C program.

dear sir,
what is the procedure to run .cpp program in linux distro debian 5 ?

just about to get around to learning c along with teaching my sons it. i had no idea where to start, the first page i checked is a bumper bonanza.

Источник

Читайте также:  Список обновлений для установки windows 10
Оцените статью