Return to site

Gnu С Compiler For Mac

broken image


Universal GNU Fortran 4.2.3 for Mac OS X 10.4 and higher. It is necessary in order to build R packages from sources that contain Fortran code. Unlike many other builds, this is a fully universal build of GNU Fortran that uses Apple's driver and supports all target architectures (i386, ppc, x8664 and ppc64). G77 is the gnu fortran77 compiler. It was last produced with gnu compiler collection (gcc) 3.4, and has since been supplanted with gfortran which supports fortran95. Because of the free-cost and high quality of the gnu copmpilers, a significant amount of software has been developed for and compiled with the g77 compiler.

You have finally made the move to become a programmer. You've registered for a course, you have your texts and manuals, and you've fired up your trusty Mac. This is exciting! You think you are all set, and then it hits: they want you to have a compiler. What the heck is that? We'll explain this and help you to get a C compiler for Mac up and running on your computer. If you are relatively new to the Mac, you can develop your skills with a course on getting started with a Mac.

Gnu С Compiler For Mac

The compiler is the last step in turning your code into a program that runs on your computer. You learn the C language to write source code. Source code cannot be understood and run by a computer in this state. It has to be converted to code that the computer can run. This is the job of the compiler. You feed your source code in to the compiler and it will either give you an executable program or a long list of error codes telling you why it couldn't make the program. Source code can be written on any platform. It is meant for humans and is the same on any operating system. The compiler, on the other hand, has to be specific for the operating system where the program will run.

Compilers usually produce code that will run faster than the alternative, interpreters. The executable program can be distributed without the source code, which makes it harder for anyone to steal the programming ideas that went into the program. A disadvantage of compilers is that the compiling step adds time to the development process because the whole program must be compiled each time a change is made.

C Compiler for Mac using Xcode

The most recommended way to get a C compiler for your Mac is to use Xcode. This uses gcc, the popular open source C compiler. The details vary for each version of OS X. We'll go through the recent versions here. You will have to register as an apple developer to get access to these tools. In order to do these installs, you will be using Terminal to work at the command line. Get a solid foundation on the Mac command line with this course.

For all of the versions of OS X, you will be downloading Xcode. Xcode is an Integrated Development Environment, or IDE. An IDE allows you to write, compile, and debug a program from one central interface. Xcode can act as an IDE for C programming. All of the install methods involve first getting Xcode, then making the gcc compiler available outside of Xcode, and then installing a newer version of gcc.

For OS X 10.6 Snow Leopard, download Xcode 3 from the Apple Developer Site. This will give you a working version of gcc, but it is an older version. If you want or need a more up to date version, that is available at High Performance Computing for Mac OS X. You can install this after installing Xcode. The files must be unzipped and installed at the command line. After that, you will need to update your Shell resource file so that the newer versions are used. Details can be found at Installing the GNU compilers on Mac OS X.

For OS X 10.7 Lion, you must get Xcode 4 from the Mac App Store. It is free, but you need to supply credit card information in order to have an App Store account. For Xcode 4.2, what you download from the App Store is an installer, which you then run. For Xcode 4.3, it is installed automatically, but it does not have gcc in the correct location. To finish the job, start Xcode and go to Preferences, Downloads, Components. Click on the Install button that is next to Command Line Tools. This gives you older versions of gcc. For the newest versions, you can use High Performance Computing for Mac OS X, as described for OS X 10.6. The process is similar and details can also be found at Installing the GNU compilers on Mac OS X.

OS X 10.8 will be very similar to 10.7. Install Xcode, then install the command line tools from the preferences. You can then get the newer versions of gcc as described for version 10.7.

OS X 10.9 Mavericks will use Xcode 5 and a revised process. Xcode 5 does not have the option to install the command line version of gcc. Instead, ensure that Xcode 5 has all available updates installed by checking from within the program. Then go to the Apple Developer Site and find the latest version of Command Line Tools (OS X Mavericks) for Xcode. It is a standard installer package. Finally, you can update the version of gcc in a manner similar to the other versions of OS X.

Other C compilers for Mac

Apple has extended the gcc compiler with a version called llvm. It incorporates more modern functioning and has a different licensing model needed by Apple for its proprietary software. Clang is an IDE for this compiler. It is designed to give more user-friendly error messages. Clang will give you the latest tools used by Apple for development. The downside is that there is no installer. It has to be built from source code, which means that you will need gcc already. Details are given at the llvm site.

Another option is given by Eclipse. Eclipse is a popular IDE for Java. The CDT plugin for Eclipse gives it the ability to compile C programs and become an IDE for C. Details can be found at the CDT page of the Eclipse site.

Now that you have a C compiler for your Mac, you can try a tutorial to write a simple program. Then get a solid start in C programming with this course for beginners. If you already know one language, extend your skills with a course for intermediate coders.

Skip to end of metadataGo to start of metadata

After installing the GNU compilers, you may want to check out the HOWTO for installing Open MPI on Mac OS X.

This HOWTO will guide you through the installation of the GNU C, C++ and Fortran compilers on Mac OS X.
Background

One of the nice things about Mac OS X is that you have a polished user interface atop a Unix operating system. This means that using command line utilities such as compilers is straightforward, making coding on your Mac easy. If you have a multi-core Mac (most should by now) and would like to run codes that use MPI to distribute processing across multiple processor cores, you should also check out the HOWTO for installing Open MPI on Mac OS X. Note that you'll need to follow the instructions on this page prior to installing Open MPI if you don't already have some set of compilers installed.

Requirements

To install the GNU compilers as described in this HOWTO, you'll need the following:

  • A Mac running 10.11 (El Capitan)
    • If you are using Mac OS X 10.6 - 10.10, check out the instructions for older versions of Mac OS X
  • An Apple App Store account
  • Internet access
Video instructions for Mac OS 10.11 (El Capitan) with Xcode 7

Rough video transcript:

Hello, and welcome to this screencast on how to install the GNU C, C++ and Fortran compilers for Mac OS 10.11 (El Capitan). In this video, I will show you how to install the compilers as well as Apple's Xcode software, which is required for the compiler installation. For this video, I am assuming you are using a Mac running Mac OS 10.11, also known as El Capitan, that you have an Apple App Store account and that you have internet access. I am also assuming you have administrator access on your Mac, allowing you to install software. If you're running an older version of Mac OS X, the installation procedure will be similar, but you can check out the link at the end of this video for the installation procedure on older versions of Mac OS X back to 10.6.

Gnu

Step 1: We'll begin by installing the current version of Apple's Xcode software, Xcode 7. To install Xcode, start by opening the App Store app by clicking on the Apple logo on the top left of the menu bar and then selecting App Store… Once the App Store app opens, enter 'Xcode' into the search and press Enter. You can now click install to install Xcode. You may be prompted to enter your Apple ID and password if you've not previously installed applications via the App Store. Xcode is a pretty big download, so depending on the speed of your internet connection it may take some time to download and install. I'll be back once the install is complete.

Step 2: Xcode has been downloaded and installed, and now we can move on to a critical second step for the Xcode install, installing the command line tools. To do this, we can use Spotlight to open the Terminal app. If you're installing compilers, I am going to assume you're at least somewhat familiar with using a terminal emulator. If not, you should still be able to do the install by following these instructions carefully. Once Terminal has opened, type in xcode-select --install. This will install the command line tools for Xcode, and you will be asked to perform the install using the typical application installation process. This may include asking you for your password.

Gnu C++ Compiler For Mac

Step 3: Now that Xcode is fully installed, we can move on to downloading the GNU compilers from the High-Performance Computing for Mac OS X website. The easiest way to get there is to open a web browser, Safari in this case. And type in 'High-performance computing Mac OS X' in the Google search. It should be the top hit. On that page, we'll grab the latest STABLE version of the GCC compiler package and click the link to download.

Gnu Compiler For Mac

Step 4: After the compilers have downloaded, we can return to the Terminal and navigate to the Downloads directory. We'll install the compilers now using the `sudo` command, and before we do so, I'm going to give you a little warning. Using the sudo command can do major damage to your computer if you aren't careful, so please type the following exactly as shown to do the install: sudo tar -xvf gcc-5.3-bin.tar -C /. If your downloaded package ends in .tar.gz, you'll need to add z to the list of flags after the tar command. This should take just a moment and will install the compilers in /usr/local.

Step 5: Now the compilers are installed, and if you're running Mac OS 10.11, you should be able to test the installation by typing gcc -v. It should show version 5.3. You can try the same with the Fortran compiler by typing gfortran -v. If they return the compiler versions as expected, you're all set. Enjoy.
- If your compilers are not installed, you may need to add the installation location to the PATH environment variable, which tells the computer where to look for command line programs.
- In that case, the easiest thing to do is go to the installation HOWTO at the link at the end of this video and check out the last section of the instructions for the installation for Mac OS 10.9 or 10.10. There are some additional instructions that may help resolve your issues. If you're still having trouble, double check you've followed the instructions exactly as given in the video and feel free to add a comment if you still need some help.
- OK, so that's it. Thank you for watching. If you have any comments, please leave them below. In case you're interested, here's another link to a video on how to install the Open MPI software for running multi-core applications on your Mac using MPI, the message-passing interface. Good luck!

Gnu compiler for mac

The compiler is the last step in turning your code into a program that runs on your computer. You learn the C language to write source code. Source code cannot be understood and run by a computer in this state. It has to be converted to code that the computer can run. This is the job of the compiler. You feed your source code in to the compiler and it will either give you an executable program or a long list of error codes telling you why it couldn't make the program. Source code can be written on any platform. It is meant for humans and is the same on any operating system. The compiler, on the other hand, has to be specific for the operating system where the program will run.

Compilers usually produce code that will run faster than the alternative, interpreters. The executable program can be distributed without the source code, which makes it harder for anyone to steal the programming ideas that went into the program. A disadvantage of compilers is that the compiling step adds time to the development process because the whole program must be compiled each time a change is made.

C Compiler for Mac using Xcode

The most recommended way to get a C compiler for your Mac is to use Xcode. This uses gcc, the popular open source C compiler. The details vary for each version of OS X. We'll go through the recent versions here. You will have to register as an apple developer to get access to these tools. In order to do these installs, you will be using Terminal to work at the command line. Get a solid foundation on the Mac command line with this course.

For all of the versions of OS X, you will be downloading Xcode. Xcode is an Integrated Development Environment, or IDE. An IDE allows you to write, compile, and debug a program from one central interface. Xcode can act as an IDE for C programming. All of the install methods involve first getting Xcode, then making the gcc compiler available outside of Xcode, and then installing a newer version of gcc.

For OS X 10.6 Snow Leopard, download Xcode 3 from the Apple Developer Site. This will give you a working version of gcc, but it is an older version. If you want or need a more up to date version, that is available at High Performance Computing for Mac OS X. You can install this after installing Xcode. The files must be unzipped and installed at the command line. After that, you will need to update your Shell resource file so that the newer versions are used. Details can be found at Installing the GNU compilers on Mac OS X.

For OS X 10.7 Lion, you must get Xcode 4 from the Mac App Store. It is free, but you need to supply credit card information in order to have an App Store account. For Xcode 4.2, what you download from the App Store is an installer, which you then run. For Xcode 4.3, it is installed automatically, but it does not have gcc in the correct location. To finish the job, start Xcode and go to Preferences, Downloads, Components. Click on the Install button that is next to Command Line Tools. This gives you older versions of gcc. For the newest versions, you can use High Performance Computing for Mac OS X, as described for OS X 10.6. The process is similar and details can also be found at Installing the GNU compilers on Mac OS X.

OS X 10.8 will be very similar to 10.7. Install Xcode, then install the command line tools from the preferences. You can then get the newer versions of gcc as described for version 10.7.

OS X 10.9 Mavericks will use Xcode 5 and a revised process. Xcode 5 does not have the option to install the command line version of gcc. Instead, ensure that Xcode 5 has all available updates installed by checking from within the program. Then go to the Apple Developer Site and find the latest version of Command Line Tools (OS X Mavericks) for Xcode. It is a standard installer package. Finally, you can update the version of gcc in a manner similar to the other versions of OS X.

Other C compilers for Mac

Apple has extended the gcc compiler with a version called llvm. It incorporates more modern functioning and has a different licensing model needed by Apple for its proprietary software. Clang is an IDE for this compiler. It is designed to give more user-friendly error messages. Clang will give you the latest tools used by Apple for development. The downside is that there is no installer. It has to be built from source code, which means that you will need gcc already. Details are given at the llvm site.

Another option is given by Eclipse. Eclipse is a popular IDE for Java. The CDT plugin for Eclipse gives it the ability to compile C programs and become an IDE for C. Details can be found at the CDT page of the Eclipse site.

Now that you have a C compiler for your Mac, you can try a tutorial to write a simple program. Then get a solid start in C programming with this course for beginners. If you already know one language, extend your skills with a course for intermediate coders.

Skip to end of metadataGo to start of metadata

After installing the GNU compilers, you may want to check out the HOWTO for installing Open MPI on Mac OS X.

This HOWTO will guide you through the installation of the GNU C, C++ and Fortran compilers on Mac OS X.
Background

One of the nice things about Mac OS X is that you have a polished user interface atop a Unix operating system. This means that using command line utilities such as compilers is straightforward, making coding on your Mac easy. If you have a multi-core Mac (most should by now) and would like to run codes that use MPI to distribute processing across multiple processor cores, you should also check out the HOWTO for installing Open MPI on Mac OS X. Note that you'll need to follow the instructions on this page prior to installing Open MPI if you don't already have some set of compilers installed.

Requirements

To install the GNU compilers as described in this HOWTO, you'll need the following:

  • A Mac running 10.11 (El Capitan)
    • If you are using Mac OS X 10.6 - 10.10, check out the instructions for older versions of Mac OS X
  • An Apple App Store account
  • Internet access
Video instructions for Mac OS 10.11 (El Capitan) with Xcode 7

Rough video transcript:

Hello, and welcome to this screencast on how to install the GNU C, C++ and Fortran compilers for Mac OS 10.11 (El Capitan). In this video, I will show you how to install the compilers as well as Apple's Xcode software, which is required for the compiler installation. For this video, I am assuming you are using a Mac running Mac OS 10.11, also known as El Capitan, that you have an Apple App Store account and that you have internet access. I am also assuming you have administrator access on your Mac, allowing you to install software. If you're running an older version of Mac OS X, the installation procedure will be similar, but you can check out the link at the end of this video for the installation procedure on older versions of Mac OS X back to 10.6.

Step 1: We'll begin by installing the current version of Apple's Xcode software, Xcode 7. To install Xcode, start by opening the App Store app by clicking on the Apple logo on the top left of the menu bar and then selecting App Store… Once the App Store app opens, enter 'Xcode' into the search and press Enter. You can now click install to install Xcode. You may be prompted to enter your Apple ID and password if you've not previously installed applications via the App Store. Xcode is a pretty big download, so depending on the speed of your internet connection it may take some time to download and install. I'll be back once the install is complete.

Step 2: Xcode has been downloaded and installed, and now we can move on to a critical second step for the Xcode install, installing the command line tools. To do this, we can use Spotlight to open the Terminal app. If you're installing compilers, I am going to assume you're at least somewhat familiar with using a terminal emulator. If not, you should still be able to do the install by following these instructions carefully. Once Terminal has opened, type in xcode-select --install. This will install the command line tools for Xcode, and you will be asked to perform the install using the typical application installation process. This may include asking you for your password.

Gnu C++ Compiler For Mac

Step 3: Now that Xcode is fully installed, we can move on to downloading the GNU compilers from the High-Performance Computing for Mac OS X website. The easiest way to get there is to open a web browser, Safari in this case. And type in 'High-performance computing Mac OS X' in the Google search. It should be the top hit. On that page, we'll grab the latest STABLE version of the GCC compiler package and click the link to download.

Gnu Compiler For Mac

Step 4: After the compilers have downloaded, we can return to the Terminal and navigate to the Downloads directory. We'll install the compilers now using the `sudo` command, and before we do so, I'm going to give you a little warning. Using the sudo command can do major damage to your computer if you aren't careful, so please type the following exactly as shown to do the install: sudo tar -xvf gcc-5.3-bin.tar -C /. If your downloaded package ends in .tar.gz, you'll need to add z to the list of flags after the tar command. This should take just a moment and will install the compilers in /usr/local.

Step 5: Now the compilers are installed, and if you're running Mac OS 10.11, you should be able to test the installation by typing gcc -v. It should show version 5.3. You can try the same with the Fortran compiler by typing gfortran -v. If they return the compiler versions as expected, you're all set. Enjoy.
- If your compilers are not installed, you may need to add the installation location to the PATH environment variable, which tells the computer where to look for command line programs.
- In that case, the easiest thing to do is go to the installation HOWTO at the link at the end of this video and check out the last section of the instructions for the installation for Mac OS 10.9 or 10.10. There are some additional instructions that may help resolve your issues. If you're still having trouble, double check you've followed the instructions exactly as given in the video and feel free to add a comment if you still need some help.
- OK, so that's it. Thank you for watching. If you have any comments, please leave them below. In case you're interested, here's another link to a video on how to install the Open MPI software for running multi-core applications on your Mac using MPI, the message-passing interface. Good luck!

Instructions for older versions of Mac OS X (10.6 - 10.10)

Instructions for installing the GNU compilers for older versions of Mac OS X (10.6 - 10.10) have been moved and are available on another page.

Tips & Warnings

I mention all but the last of these tips and warnings in the text above, but it doesn't hurt to list them a second time...

  • Beware that using sudo can do major damage to your computer if you aren't careful.
  • Note that after installing Xcode, you also need to perform a critical additional step.
    • Launch Xcode and install any available updates. Quit Xcode.
    • Launch Terminal.app (in /Applications/Utilities, hopefully you know that)
    • Install the Command Line Tools for OS X by typing

      This will open a dialog box to install the Command Line Tools for Xcode package. Install following the standard procedure.

  • If the correct version of gcc is not being found at the command line after installation, it is possible that you're using a terminal emulator that reads the .bashrc file rather than the .bash_profile file. To confirm, do the following:
    • Open a new terminal window using your terminal emulator of choice. This will reread the either the .bash_profile file or the .bashrc. If the new gcc version is not returned when typing

      then your terminal emulator may be reading the .bashrc file.

    • You can fix this one of two ways
      • Create a symbolic link called .bashrc that points to .bash_profile by typing

      • Modify the order of directories that are searched for commands by typing

Related



broken image