Section 0e

Installing C Tools for Mac


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Installing the C Tools onto the Mac Operating System

In order to use your Mac to program in C, you will need to download a set of command line tools. You can download these tools either through the command line on your computer itself or through Apple’s developer website. I will be giving a step-by-step guide for installing the command tools through each of these methods.

Installing C Tools via Command Line

In order to install these command line tools, you will first need to open Terminal, which does not require any installation or downloading.

Picture of Terminal in Finder window

When you open Terminal, you should see the following window:

Picture of Terminal

Type “xcode-select --install" into your command line

Picture of xcode installation command in command line.

You will receive the following message. Click "install." Once you click install, you will be shown the Command Line Tools License Agreement. Click "agree."

Picture of installation request.

Once you agree to the license agreement, the command line tools will begin downloading onto your device and you will receive a message once installation is complete.

You can verify that the command line tools have downloaded onto your device and view additional information on the version you have by typing “gcc -v” into your command line.

Picture of gcc -v in terminal.

Installing C Tools via Apple's Developer Website

You can download the command line tools through Apple. In order to do so, you fill need to go to Apple's developer website and create a developer account. Making a developer account with Apple is free, however you will need to provide them with some information about yourself and agree to their Terms of Service. here. You will be given the option to choose which versions of the command line tools you would like to download. To download a specific version, click the "+" to the left of the description and click on the prodided file.".

Picture of Apple's developer website.

 

For the purposes of installing command line tools onto your computer for C programming, you will need to download the following package. You can begin downloading this package by clicking on “Command Line Tools for Xcode 13.5.dmg” as shown below.

Picture of download sites for Eclipse

 

Once the file is downloaded, double click on it. It will unzip itself and install the command line tools. If there are any option choices provided, just accept the options offered.

Once you have finished installing the command line tools with the window above, you can verify that the tools have successfully downloaded and view more information on the version that you have by typing “gcc -v” into your command line.

gcc -v command in terminal

At this point, the GCC compiler should be completely installed on your device. Now you can create a quick little test program to see everything working. Using the editor of your choice (this example uses Atom) create a small C program called test.c with the same information as this example or a program of your own design. There are a few vital pieces that a C program must have in order to function properly. You will see at the top of the file there is a #include at the top of the file that has stdio.h inside of two carrots. This is a C requirment as well as the int main() and the open and close curly braces that enclose a integer return statement.

testFile.

Once the test file has been written and saved, return to the command line and run the following command to compile it.

compile.

If nothing happens and the terminal returns a screen like the following, then the program compiled properly wihtout any errors or warning.

compile2.

Now, the program can be run. Type in the following command and hit enter.

run command.

After enter is pressed, the output of the program should look like the following.

output

Congratulations! You have now run your first C program using the GCC compiler via MAC terminal.

 

One extra thing for Mac Computers . . .

Okay, there is one more thing that you have to do on Mac computers. If you conduct any significant math operations, you have to add one more switch to your compiling operation. It is -lm (dash ell em), and would look like the following:

gcc -Wall test.c -lm -o test

After that, everything else is the same. Enjoy!