Changing GCC compiler from version 4.2 to 4.0

Discussion in 'Mac Programming' started by SAEinSDSU, Feb 22, 2010.

  1. SAEinSDSU macrumors newbie

    Feb 17, 2010
    I am in a computer programming class using the assembly language. I am currently running GCC 4.2 which uses the 64 bit compiler...however a 32 bit compiler is used in class...and following along with different registers/code in assembly is nearly impossible. I need to change the path that my compiler uses so that 4.0 is used instead...however I want to be able to change it back if I see the need for it in the future. I was given this command for my terminal by a friend to change the version used.

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

    however he also gave me this warning/advice at the end of the email.

    Oh, one more thing Don't forget to make a record of your links before you change them! 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 If you want to change back, here's the code I would use: cd /usr/bin sudo rm cc gcc c++ g++ sudo ln -s gcc-4.2 cc sudo ln -s gcc-4.2 gcc sudo ln -s c++-4.2 c++ sudo ln -s g++-4.2 g++ You'll want to check your /usr/bin and look for a file that's like "gcc-4.x". If it isn't 4.0 or 4.2, substitute the version numbers above for the version number that you have. – Alex Nov 3 at 16:29

    This explanation of how to add a new path just does not make sense to me...if anyone could give me a more detailed explanation of how to make a record of my links...or whatever that means.

    Thank you for any help
  2. LPZ macrumors 65816

    Jul 11, 2006
    Why don't you just use the gcc-4.0 command directly?

    For example, to compile foo.c just enter

    gcc-4.0 -o foo foo.c

    No real need to change anything.
  3. broken-chaos macrumors regular


    Sep 2, 2009
    Toronto, Ontario
    Also, if you're building applications with something like autotools (i.e., ./configure; make) you should be able to just set the CC and CXX variables to the correct compiler, specifically when running ./configure.

    If you just need 32-bit output, but don't have a specific need for gcc-4.0, you could just use "-arch i386" in your CFLAGS/CXXFLAGS/LDFLAGS (i.e., "gcc -arch i386 [...]" on the command line).

    If you *absolutely must* force your Terminal to use gcc-4.0 from the command gcc, I'd suggest just adding a bash alias (either in your .profile/.bashrc, or just running "alias gcc='gcc-4.0'" when you need it that way).

    (Oh, you could also, if you just need 32-bit compiling but not gcc-4.0, run "alias gcc='gcc -arch i386'", so you don't have to keep typing -arch i386 every time you compile something.)
  4. mslide macrumors 6502a

    Sep 17, 2007
    I think your friend is giving you bad advice. I would not change around the system's soft links, like your friend suggests. No offense intended, but I especially recommend that you not do anything that requires 'sudo' since you don't understand what he is telling you.

    I would use gcc 4.2 but use the -arch i386 option so it generates 32-bit code. My second choice would be to just use gcc-4.0 directly. If you feel like you really must have 'gcc' invoke gcc-4.0, then I'd recommend either using an alias or creating soft links in your home directory (like your friend suggests in the warning part of his email).
  5. SAEinSDSU thread starter macrumors newbie

    Feb 17, 2010
    The problem I am having is that I am using Xcode to debug programs written in C to show them in assembly. Using the build and run within the xcode automatically uses the 4.2 not 4.0...I am not compiling the programs through the terminal I do not see how the -arch i386 option could be invoked through Xcode. Sorry I did not specify that in the there a way to set Xcode to use 4.0 without changing my systems soft links like broken sort of suggested?
  6. autorelease macrumors regular

    Oct 13, 2008
    Achewood, CA
    Ack! Don't mess with softlinks!

    If you're using Xcode, just double-click your target's icon, and, under the Build tab of the Target Info dialog, change "C/C++ Compiler Version" from GCC 4.2 to GCC 4.0.

    All the compilation options you can think of can be changed from this dialog.
  7. SAEinSDSU thread starter macrumors newbie

    Feb 17, 2010
    ah thank you that did the trick...sorry about the confusion on how I was compiling earlier...I will try and be more clear next time
  8. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Or rather than doing that just change the target architecture to i386 in the project settings. No need to change the gcc version used then.

Share This Page