59

I am using OS 10.9 on mac machine. I want to know the version of gcc I am using. So I tried gcc --version on terminal and it results :

$ gcc --version
Configured with: --prefix=/Applications/Xcode5-DP.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode5-DP.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.1.58) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

Here in output, there is no detail related to gcc but clang is there. I am confused whether gcc command executes clang or gcc(gnu).

subhash kumar singh
  • 2,716
  • 8
  • 31
  • 43

6 Answers6

36

You seem to not actually have gcc on your path. As of recent versions of Xcode, it installs a "gcc" that is instead a link to Clang.

danfuzz
  • 4,253
  • 24
  • 34
  • could I assume that I am running gcc 4.2.1 and clang will follow all the standards of gcc 4.2.1. – subhash kumar singh Dec 05 '13 at 21:17
  • I don't know how closely Clang matches gcc. I do know, though, that they aim to be source compatible, including lots of (all of?) the gcc extensions. – danfuzz Dec 05 '13 at 21:22
  • 3
    @danfuzz not all, see [Intentionally unsupported GCC extensions](http://clang.llvm.org/docs/UsersManual.html#intentionally-unsupported-gcc-extensions) and [GCC extensions not implemented yet](http://clang.llvm.org/docs/UsersManual.html#gcc-extensions-not-implemented-yet) – tab Dec 05 '13 at 21:44
26
gcc -dumpversion | cut -f1 -d.

-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)
serghei
  • 3,069
  • 2
  • 30
  • 48
19

The tools supplied by Apple have been switched from GCC to Clang. The gcc command is linked to clang as a convenience. In OS X 10.9, you do not have GCC on your system unless you have installed it independently of Apple packages.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
4

In case you installed gcc via brew install, it might've got installed as gcc-11.

You can run brew info gcc to get path where it is installed and get exact name of the binary by listing the directory.

$ brew info gcc
gcc: stable 11.2.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/11.2.0_3 (2,163 files, 459.8MB) *
...
$ ls /usr/local/Cellar/gcc/11.2.0_3/bin
c++-11                  gcc-ar-11               gcov-dump-11                gfortran                x86_64-apple-darwin21-g++-11        x86_64-apple-darwin21-gcc-ranlib-11
cpp-11                  gcc-nm-11               gcov-tool-11                gfortran-11             x86_64-apple-darwin21-gcc-11        x86_64-apple-darwin21-gcc-tmp
g++-11                  gcc-ranlib-11               gdc                 lto-dump-11             x86_64-apple-darwin21-gcc-ar-11     x86_64-apple-darwin21-gdc-11
gcc-11                  gcov-11                 gdc-11                  x86_64-apple-darwin21-c++-11        x86_64-apple-darwin21-gcc-nm-11     x86_64-apple-darwin21-gfortran-11

Then using gcc-11 -v will get you actual version of gcc installed.

$ gcc-11 -v
Using built-in specs.
COLLECT_GCC=gcc-11
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_3/bin/../libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: ../configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Homebrew GCC 11.2.0_3) 
effeKtSVK
  • 125
  • 1
  • 11
2
gcc -dumpversion | cut -f1 -f2 -f3 -d.
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Yokey21
  • 21
  • 3
0

gcc --version you can find your gcc path.

sudo ln -s /Library/Developer/CommandLineTools/usr/bin/gcc /usr/local/bin/gcc

curits
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 02 '23 at 13:11