open source, neuro, learning, collaboration, sound theory, solid results

gcc 4.6.1 on osx lion

got gcc 4.6.1 installed on lion.   why do you want gcc?

basically, better warnings, faster compilation and better optimization.   i was mainly interested in the fact that it finds errors that lion’s 4.2 misses.

i tried to simplify these instructions a bit (which are excellent):

if you have homebrew installed, the first couple steps become:

1.  brew install gmp

2.  brew install mpfr
3.  then get mpc 0.8.1 from here:
../configure --prefix=$HOME/my_gcc --with-gmp=/usr/local/Cellar/gmp/5.0.2/lib/ --with-mpfr=/usr/local/Cellar/mpfr/3.0.1/lib/
 make install
note — you may get an error similar to this:
in that case open the relevant failing file and replace GMP_RND with MPFR_RND
then compile gcc 4.6 via :
../configure --prefix=$HOME/my_gcc --enable-checking=release --with-gmp=/usr/local/Cellar/gmp --with-mpfr=/usr/local/Cellar/mpfr --with-mpc=/Users/stnava/my_gcc/ --program-suffix=-4.6.1
make   # could take all day
sudo make install
then create a Makefile:
CFLAGS=-c -Wall
    $(CC) $(LDFLAGS) $(OBJECTS) -lpthread -std=c++0x  -o $@
    $(CC) $(CFLAGS) $< -o $@
in the Makefile, the $(CC) lines shoudl begin with a tab, all others left-justified.
then compile the test.cpp by typing make.
#include <iostream>
using namespace std;
int main()
// below some funky new C++0x syntax ( the next ISO C++ standard. )
  cout<<[](int m,int n){return m+n;}(2,4)<<endl;
  std::cout <<" go surfing " << std::endl;
it should print the number 6 then say "go surfing."


2 responses

  1. Be careful if you copy and paste these commands. WordPress does some auto-formatting with hyphens and double hyphens which will result in errors like
    configure: error: invalid variable name: `–prefix’

    October 1, 2011 at 2:32 am

  2. Fixed in the current version — must choose “preformatted” option to prevent this type of thing from happening

    October 2, 2011 at 12:07 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s