How To Download Gcc Compiler For Mac

broken image


Oct 29, 2020 In this tutorial, we will learn to install C in Windows, Mac, and Linux. Install C on Windows. We will use an open-source Integrated Development environment named Code::Blocks which bundles a compiler (named gcc offered by Free Software Foundation GNU), editor and debugger in a neat package. Gcc Compiler Mac Then It. If gcc is already installed on your mac then it will show as no input files. If you dont have gcc installed then you will get dialogue box saying you to download and install gcc and its respective command line tools.

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.

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.

How To Download Gcc Compiler

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.

Download Gcc Compiler Windows 10

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.

THIS PAGE HAS BEEN DEPRECATED. SEE THE SPRING 2015 SITE.

Installing G++ on a Mac

This section is intended to get you quickly started with C++ programming on your Mac. We'll be installing GCC 4.8.1 and GDB through a tool called Homebrew. If you want an additional guide on all of the following steps (except for installing GCC), the one by Moncef Belyamani is quite helpful. When you follow it, ignore anything about installing Ruby; that is, stop after setting up git.

Homebrew

Homebrew 'installs the stuff that you need that Apple don't'. It's like Ubuntu's apt-get, where one can install packages easily from repositories. Instead of having to download, configure, and install something yourself, all you need to do is run one command, and Homebrew will take care of the rest for you.

Pre-requisites

Homebrew requires that you have either Xcode or the Xcode command line tools installed on your Mac. Xcode is a free integrated development environment similar to Eclipse designed by Apple and mainly intended for iOS development or targeting the clang compiler. In this class, we will focus on gcc.

Xcode is quite a big install, so if you do not want to install it, you can get away with just installing the Xcode command line tools. See a Stackoverflow discussion for instructions on how to install the command line tools regardless of whether you have Xcode installed.

Installing Homebrew

You need xcode command line tools to install Homebrew. It is very easy to install Homebrew. Open your terminal, and run the following command:

If this doesn't seem to do anything, try killing it (CTRL C) and running it again. Or checkout homebrew website.

GCC and GDB

Installing GCC

First of all, you should make sure that your Homebrew is up-to-date. Check to see if it is so with the following:

As mentioned before, installing packages with Homebrew is very easy. First, we will add the repository from which the GCC package is available, so that Homebrew knows where to find the package we want. The repository is at https://github.com/Homebrew/homebrew-versions.

We do this by using the brew-tap command. Keep your terminal open, and run the following command. (For more information on how brew-tap works, visit the Homebrew docs):

Next, we will actually install the GCC package. Run the following command:

It might take long time before the installation is complete. If you run into any issues, you can debug with:

When done, run the following:

The result should look like this:

For

USC Wireless Warning

Many people have had issues running the brew install commands while connected to USC Wireless. If you are having trouble, you can either try using a wired connection, a different wireless connection, or do the following:

  1. Download a homebrew cache
  2. Open Finder, press CMD (command) + SHIFT + G and type /Library/Caches/Homebrew
  3. Extract the contents of the .zip you downloaded inside of the folder you opened in the previous step. Do not extract any of the .tar.bz2 or .tar.gz inside of the .zip folder.This should look as follows:

  4. Run brew install gcc48 in the Terminal as instructed above.

Using G++

To compile with the newly installed G++ compiler, use g++-4.8.

(Advanced) Aliasing g++

If you prefer calling g++ directly, you can also create a bash alias, as follows:

Put these two lines at the end of the file ~/.bashrc, and run:source ~/.bashrc

For more information on bash alias, take a look at the GNU Docs.

Installing GDB

Here also we use Homebrew. The following instruction has been taken from GDB on OS X Mavericks and Xcode 5 guide. To install, run the following brew command.

Check if it's installed:

The result should be gdb version 7 or higher.

Codesigning gdb

gdb is not going to debug yet. You'll get an error message like 'please check gdb is codesigned'. You need to create a certificate and sign gdb. By doing so you're telling the operating system that gdb is authorized to attach to other processes for debugging purposes. The following instructions have been taken from this Code Signing guide.

Download Gcc Windows

  1. Open application 'Keychain Access' (/Applications/Utilities/Keychain Access.app)
  2. In Keychain Access, select the 'login' keychain in the 'Keychains' list in the upper left hand corner of the window.

  3. Open the menu item in /Keychain Access/Certificate Assistant/Create a Certificate...

  4. Choose a name ('lldb_codesign' in the example, but you can use anything you want), set 'Identity Type' to 'Self Signed Root', and set 'Certificate Type' to 'Code Signing'. Click 'Create'.

  5. Click continue, continue and done.

  6. Click on the 'My Certificates' category on the left side and double click on the new 'lldb_codesign' certificate.

  7. Open the context menu for 'Trust' (click the triangle) and change the following:When using this certificate: Always Trust

  8. Now close this window, and enter your login password to confirm this change.

  9. Option-drag (this meaning holding the option key down and dragging) the new 'lldb_codesign' certificate from the login keychain to the System keychain in the Keychains pane of the main Keychain Access window to make a copy of this certificate in the System keychain. You'll have to authorize a few more times, set it to be 'Always trusted' when asked.

  10. Switch to the 'System' keychain and drag a copy of the 'lldb_codesign' you just made onto the Desktop.

  11. Switch to Terminal and then run the following command (copy paste it!): sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/lldb_codesign.cer

  12. Then right click on the 'lldb_codesign' certificate in the 'System' keychain (not 'Login') and select 'delete' to delete it from the 'System' keychain.

  13. Then reboot your system/computer.

  14. Finally you can sign gdb:codesign -s lldb_codesign /usr/local/bin/gdb

  15. If this command doesn't work...then panic! Just kidding, be sure that you have gdb installed and that gdb is actually installed in /usr/local/bin. You may want to try 'which gdb' in your Terminal to figure out where it is.

  16. Finally, remove the lldb_codesign.cer file that's sitting on your desktop, and gdb should be working at this point. :)





broken image