Setting GCC 4.2 as the default compiler on Mac OS X Leopard

前端 未结 6 1665
小蘑菇
小蘑菇 2020-11-29 18:53

I\'m sure there must be a way to do this. As you are probably aware the latest versions of Xcode (and in fact I think all versions of Xcode) on Leopard come with GCC 4.0.1 a

相关标签:
6条回答
  • 2020-11-29 19:36

    Command line usage for all configure scripts:

      cd /usr/bin
      rm cc gcc c++ g++
      ln -s gcc-4.2 cc
      ln -s gcc-4.2 gcc
      ln -s c++-4.2 c++
      ln -s g++-4.2 g++
    

    Make a record of the current link targets, so you can restore them if you want to.

    If you don't want to change the system wide settings, add a directory into PATH before /usr/bin (say, $HOME/bin), and make the symlinks there

    I haven't tested whether this affects Xcode projects, since I don't use Xcode (only command line).

    0 讨论(0)
  • 2020-11-29 19:36

    In the Project or Target Info Window set the build setting "C/C++ compiler version" (GCC_VERSION).

    Or in the Target Info Window you can change the "System C rule" to your favorite GCC version.

    Update: Regarding the command line I would leave to Leopard the decision of what should be the default compiler. If you want to use a different compiler with tools like Autotools configure you had better to define the CC variable.

    CC=gcc-4.2 ./configure
    

    or

    export CC=gcc-4.2
    
    0 讨论(0)
  • 2020-11-29 19:50

    Since I need to build things where CC env is ignored and I end up switching often, I wrote a simple minded gcc_select in Python. Thought I may as well post it here. Invoke it with arg either 4.0 or 4.2 or no arg to see current symlinks. Would need modification if you have versions other than 4.0 and 4.2:

    #!/usr/bin/python
    import sys
    import os
    
    os.chdir('/usr/bin')
    
    files = ['cc', 'gcc', 'c++', 'g++']
    
    if '4.0' in sys.argv:
      ver = '4.0'
    elif '4.2' in sys.argv:
      ver = '4.2'
    else:
      print "Unknown gcc version.  Current setting:"
      os.system('ls -al %s' % ' '.join(files))
      sys.exit(1)
    
    os.system('rm %s' % ' '.join(files))  
    for f in files:
      os.system('ln -s %s-%s %s' % (f, ver, f))
    
    print "Changed to gcc version %s" % ver
    
    0 讨论(0)
  • 2020-11-29 19:59

    Since neither Apple nor Darwin Ports have the gcc_select program to change the default version of the System compiler (as exists on GNU/Linux), I would like to be on the safe side with XCode (and the rest of the system) and would recommend to leave the symbolic links as they are and instead setup environment variables that overrides which version of GCC to use.

    In my .profile file I have the following

    export CC=/usr/bin/gcc-4.2
    export CPP=/usr/bin/cpp-4.2
    export CXX=/usr/bin/g++-4.2 
    

    And I successfully compiled the following libraries with GCC 4.2 from source.

    • OpenSSL
    • libjpeg
    • libpng
    • zlib
    • gst

    However... I could not get Boost 1.39 to acknowledge the environment variables, so to compile Boost with GCC 4.2 I needed to change the symbolic links in /usr/bin/ so they pointed to gcc v4.2

    After the long while the Boost libraries were finished compiling with GCC 4.2 I restored the symbolic links back to the original System version gcc-4.0.

    0 讨论(0)
  • 2020-11-29 19:59

    Im my experience (limited), changing CC in .profile does not change Lion's (10.7.2) defaulting to i686-apple-darwin11-llvm-gcc-4.2. I wonder if this has anything to do with Apple's own sym linking: a partial: ls -la /usr/bin | grep .*gcc.* :

    lrwxr-xr-x     1 root   wheel        12 25 oct 19:31 cc -> llvm-gcc-4.2
    lrwxr-xr-x     1 root   wheel        12 25 oct 19:31 gcc -> llvm-gcc-4.2
    lrwxr-xr-x     1 root   admin        32 25 oct 19:31 llvm-gcc-4.2 -> ../llvm-gcc-4.2/bin/llvm-gcc-4.2
    

    I am wary about breaking these and adding my own to usr/bin/gcc-4.2 per Martin v. Löwis's answer.

    0 讨论(0)
  • 2020-11-29 19:59

    I might be wrong, but I thought that was what Xcode-select was for?

    xcode-select --switch /path_to_tool_suite
    

    As I said, I'm not 100% on this, but I believe it will set the default for all programs including Terminal and other apps that calls into the OS to use a compiler.

    0 讨论(0)
提交回复
热议问题