Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update GCC on OSX

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 application, in C++, g++ comes up saying it is version 4.0.1 but when I look for commands starting with g I also see g++-4.2. Is there any way of making 4.2 default rather than 4.0.1, and also is there a way to updating gcc to the latest version 4.4.0?

EDIT: Ok, so I installed macports and installed gcc4.4 and it shows up on terminal as gcc-mp-4.4 and how do I make it default with gcc_select, like what are the commands and stuff. Thanks.

like image 926
Karan Bhamra Avatar asked May 08 '09 02:05

Karan Bhamra


People also ask

How do I find gcc version on Mac?

$ 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) * ... Then using gcc-11 -v will get you actual version of gcc installed.

What is gcc in Mac?

gcc is the C and C++ compiler developed by GNU project. It is widely adopted as the default compiler of UNIX-like systems. If you are using a Mac, you may also get gcc by installing Xcode (Developer) Tools in the Mac OS X installation Disc #1.


2 Answers

If you install macports you can install gcc select, and then choose your gcc version.

/opt/local/bin/port install gcc_select 

To see your versions use

port select --list gcc 

To select a version use

sudo port select --set gcc gcc40 
like image 164
Milhous Avatar answered Oct 11 '22 05:10

Milhous


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

like image 42
Briand06 Avatar answered Oct 11 '22 04:10

Briand06