score:119

Accepted answer

just type

gcc --version

in any terminal near you.. ;-)

score:3

you can also use gcc -v command that works like gcc --version and if you would like to now where gcc is you can use whereis gcc command

i hope it'll be usefull

score:9

the answer is:

gcc --version

rather than searching on forums, for any possible option you can always type:

gcc --help

haha! :)

score:14

#include <stdio.h>

int main() {

  printf("gcc version: %d.%d.%d\n",__gnuc__,__gnuc_minor__,__gnuc_patchlevel__);
  return 0;
}

score:28

gcc -dumpversion

-dumpversion print 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 --version might 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 --version output will contain something like android (5220042 based on r346389c) clang version 8.0.7 (it's real version string)

Related Query

More Query from same tag