Update GCC on OSX

前端 未结 9 952
醉话见心
醉话见心 2020-11-28 19:08

So I am a new programmer and I just installed XCode on my Macbook to get the GCC. I think Xcode is the only way for getting GCC on OSX. Now when I run my Hello World applica

相关标签:
9条回答
  • 2020-11-28 19:52

    You can have multiple versions of GCC on your box, to select the one you want to use call it with full path, e.g. instead of g++ use full path /usr/bin/g++ on command line (depends where your gcc lives).

    For compiling projects it depends what system do you use, I'm not sure about Xcode (I'm happy with default atm) but when you use Makefiles you can set GXX=/usr/bin/g++ and so on.

    EDIT

    There's now a xcrun script that can be queried to select appropriate version of build tools on mac. Apart from man xcrun I've googled this explanation about xcode and command line tools which pretty much summarizes how to use it.

    0 讨论(0)
  • 2020-11-28 19:54

    I know it is an old request. But it might still be useful to some. With current versions of MacPorts, you can choose the default gcc version using the port command. To list the available versions of gcc, use:

    $ sudo port select --list gcc

    Available versions for gcc:
    gcc42
    llvm-gcc42
    mp-gcc46
    none (active)
    

    To set gcc to the MacPorts version:

    $ sudo port select --set gcc mp-gcc46

    0 讨论(0)
  • 2020-11-28 19:55

    I'm just dropping in to say that using a soft link to accomplish this is a terrible, no-good, horrible idea.

    One of the key things about writing software is reproduceability - you want to be able to get the same results every time. These systems are so complex that you want to reduce all invisible sources of error.

    Having a soft link is an invisible source of error. It's the sort of thing you'll forget in a month, then move to a different machine, and wonder why you are getting different results - or, you'll try to upgrade your system, and you'll get weird errors because it's not expecting a softlink there.

    Moreover, this isn't guaranteed to work - in particular, it's not clear that you will get the correct system include files, which have certainly changed between iterations of gcc.

    gcc_select is a systematic way of doing the same thing which will work predictably, or in the very worst case you can file a bug report and get an eventual fix or fix it yourself.

    Unfortunately :-( gcc_select does not affect which compiler XCode uses so it's not the way to go if you need to work in XCode (which I do). I still don't know what that way might be.

    0 讨论(0)
  • 2020-11-28 19:55

    use "gcc_select -l"

    > gcc_select -l

    gcc40 mp-gcc44

    > gcc_select mp-gcc44

    0 讨论(0)
  • 2020-11-28 19:57

    You can install your GCC manually

    either through

    sudo port install gcc46
    

    or your download the source code from one of the mirrors from here for example here

    tar xzvf gcc-4.6.0.tar.gz cd gcc-4.6.0 ./configure make

    well if you have multiple version, then through you can choose one

    port select --list gcc
    

    remember port on mac is called macport https://www.macports.org/install.php and add add the bin into your path export PATH=$PATH:/opt/local/bin

    0 讨论(0)
  • 2020-11-28 20:00

    The following recipe using Homebrew worked for me to update to gcc/g++ 4.7:

    $ brew tap SynthiNet/synthinet
    $ brew install gcc47
    

    Found it on a post here.

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