why do i have 2 versions of gcc and g in Mac OS X?

Discussion in 'OS X Yosemite (10.10)' started by oat, Feb 14, 2015.

  1. oat macrumors newbie

    Joined:
    Nov 8, 2014
    #1
    I just had a fresh re-installation of Mac OS X Yosemite before I install Xcode and then CommandlineTools.



    It seems I have two versions of gcc and g++ in the following two directories:

    /usr/bin (both files are 14kb) and
    /Library/Developer/CommandLineTools/usr/bin (g++ is just an alias and gcc is 19kb)

    Type "which gcc" in the Terminal gives me "/usr/bin/gcc", so did "which g++" which gives me "/usr/bin/g++", and this means the system will only use the gcc and g++ in /usr/bin



    So, my questions are:

    1. why do I have two versions of gcc and g++?

    2. why the gcc and g++ installed with CommandLineTools is not specified as the default ones?

    3. How do I ask the Mac OS X to point to the gcc and g++ in the directory "/Library/Developer/CommandLineTools/usr/bin"?


    BTW, i installed CommandlineTools according to the following:

    http://railsapps.github.io/xcode-command-line-tools.html



    However, I got a different output by typing "gcc --version" (difference hightlighted):

    Configured with: --prefix=/Application/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) Target: x86_64-apple-darwin14.0.0 Thread model: posix



    ... rather than /Library/Developer/CommandLineTools/usr as shown in the web page above ...



    I'm quite confused about which gcc/g++ is actually being used by Mac OSX currently ...
     
  2. Dargoth macrumors regular

    Dargoth

    Joined:
    Oct 27, 2014
    #2
    Currently, gcc and g++ in /usr/bin are what's known as shims. They are capable of automatically determining the path to their respective utilities, and then forwarding everything they receive to them. That path can either be the command line tools directory you mentioned above, or Xcode.
     
  3. oat thread starter macrumors newbie

    Joined:
    Nov 8, 2014
    #3
    Thanks, Dargoth!

    Does it mean, there's no need for frustration as the gcc and g++ in /usr/bin will forward whatever related to these two programs to the latest gcc and g++ installed via CommandLineTools in the system?
     
  4. Dargoth macrumors regular

    Dargoth

    Joined:
    Oct 27, 2014
    #4
    Yep!
     
  5. leman macrumors 604

    Joined:
    Oct 14, 2008
    #5
    You might also want to check out the documentation for xcode-select

    man xcode-select
     
  6. Dargoth macrumors regular

    Dargoth

    Joined:
    Oct 27, 2014
    #6
    Hah, I did leave that out didn't I. xcode-select is what determines what the shims point to. Thanks for the catch! :)
     

Share This Page