Member Since: Apr 29, 2006
Location: St. Somewhere
Mac Specs: iMac 27" 3.4 GHz, 256 GB SSD, 2 TB HDD, 8 GB RAM
02-24-2007, 07:14 PM
Assuming gcc is installed, the simplest way may be to compose a make file and use the make utility.
Here is an example. Assume you have file program.c that you want to compile and link so that the result is the executable "program".
In the same directory as program.c, place a file called Makefile - the "M" should be uppercase. Create this file with your favorite editor and put the following lines in it:
# Make file to create the "program" executable
program : program.c
cc -o program program.c
Now, to compile and link in one step, just issue the command:
That's it! Much simpler than manually typing in the whole "cc" command.
BTW, cc is normally aliased to gcc, hence the use of the "cc" command vs. the "gcc" command. Using "cc" instead makes the Makefile more portable, since many *nix systems have a native "cc" and don't need gcc.
My Macs: iMac 27" 3.4 GHz, Mac Pro 3.2 GHz, PowerMac G5 Quad 2.5 GHz, G4 Cube with 1.2 GHz Upgrade
My iStuff: 64GB iPhone 5, 64GB iPad4, 30GB iPod Video, 16GB iPod Touch
My OS': Mac OS X Lion, Mac OS X Snow Leopard, Mac OS X Tiger, Mac OS 9.2.2, openSUSE 10.3
I was on the Mac-Forums honor roll for September 2007