How to Compile Code on a Mac
If you intend to program code on the Apple Macintosh platform, you will need to install a compiler. Apple offers a bundle of development tools for the Mac through the Apple Developer Program. The bundle is called “Xcode” and it includes a compiler. You can also install pre-compiled versions of the Gnu C Compiler on a Mac and use GCC to compile code.
Instructions
-
-
1
Connect to the Apple Developer Program website and register as an Apple developer. Apple offers paid programs with the latest tools as well as free access to earlier versions of Xcode.
-
2
Download and install Xcode from the Apple Developer Program website. The Xcode package is over 4 GB and may take some time to download, depending on the speed of your Internet connection.
-
-
3
Write or download source code in C or C++. If you download a source package from the Internet, it will likely contain multiple files and directories. Extract the package from its archive and make note of where it has been created relative to your home folder; for example, if it is in your “Downloads” folder.
-
4
Open a terminal window. You use the Terminal application in OS X to interact with the operating system on the command line. The Terminal application is in the Utilities folder, under your Applications folder.
-
5
Change to the directory with your source code via the command line in your terminal window. Use the "cd" command and the path to the folder where your source is installed. For example, use "cd Downloads/source-tree" if you stored the source in the source-tree folder within the Downloads folder.
-
6
Execute the make command if a Makefile is present. If you are compiling a newly written source file, use the "gcc" command with the appropriate flags, such as "gcc -o outputfile file1.c".
-
1
Tips & Warnings
You can download a free, pre-compiled version of GCC for OS X and bypass the Apple Developer Program. Xcode includes a graphical user interface and a variety of other tools, while the pre-compiled GCC can only be run from the command line.