During a programming class back in 2006, I had to find a way to write and compile C programs on my iBook G4. This was one of the ways I found to do that job.
Required:
- Apple Developer Tools (available on OS X Install DVD)
- A text editor (I use TextWrangler)
Steps:
- Install Apple Developer Tools on the Mac OS X Install DVD by inserting Disk 1 and choosing Developer Tools.
- Write a program with a text editor and save it with the extension .c
- Open Terminal by navigating to Applications > Utilities > Terminal
- Type
gcc
with a space afterwards - Drag the file with the .c extension to the Terminal window to place the location of the file.
- Press Enter.
- Type
~/a.out
- Press Enter.
- Watch your program come alive!
This will generate a file called a.out inside your user folder.
[tags]programming, Mac OS X, Terminal[/tags]
instead of resorting to the default a.out you can use gcc the way it was meant to be used!!!
…………………….
gcc -o -Wall name file.c
…………………….
where name is the name of the program gcc will create,
file.c is the file and perhaps extension of the code you have created.
-o is to open new/rewrite in this case name (*if name already existed, it would overwrite without a second thought)
-Wall is another option which tells gcc to show all errors it encounters during compiling. (*this is optional)
i used this way… but the gcc command wasn’t there:
“-bash: gcc: command not found” << this is what was written
what 2 do?
@mad angel: This is likely because you do not have OS X Developer tools installed. This is not included in the stock installation, you need to insert the install DVD and choose “additional software”.
ware i can download the Compiled C for mac os x
10.6.2
it is ./a.out(enter) i think
this is what i did ~ mq_quirino$ /Users/mq_quirino/Documents/C practice files/Lorem Ipsum.c/Lorem Ipsum3.c ~/a.out
then i got
-bash: /Users/mq/Documents/C practice files/Lorem Ipsum.c/Lorem Ipsum3.c: Permission denied
im trying to compile and execute ny c program using this method,but im getting this message error from the terminal: ” bash: gcc: command not found”
Looks like GCC isn’t installed. Did you follow step #1? “Install Apple Developer Tools on the Mac OS X Install DVD by inserting Disk 1 and choosing Developer Tools.”
It ain’t working on my mac.. i’m responded with a pop up saying ” you can’t save the fil with this extension” .. so wat else can I do??
First u have to download gcc compiler…..download XCode first…..
If you are working in your home directory, as is the case in the above example, then ~/a.out will work perfectly well. The command line of ./a.out will work from any directory where one is attempting to run their a.out. Explanation: The symbol tilde (~) refers to the user’s home directory. The symbol dot (.) refers to the current directory. By default, in Unix/Linux, the current directory is not in the command search path. Therefore, to execute something in the currrent directory, you have to explicitly give the directory in the command invocation. This is considered a security feature to thwart execution of imposter commands that someone may have placed into the directory that you just happen to be in. (This was not a characteristic of the Bell Labs Unix of the seventies.)
i got a message saying permission denied
i have xcode but it still shows the same statement
I have Mac OS X 10.8.1 and installed Xcode 4.4.1.I have also installed TextWrangler and write a code in C and save the file with .C extension.After that When I was trying to compile it by using
gcc /Users/anirudhsinghal/Documents/ADS1.C
it has displayed the error message as -bash: gcc: command not found
Aditya, you probably need to install the Command Line Tools from within Xcode (Preferences > Downloads > Install). They’re not installed by default.
Hello i’ve done it successfully thank you for the guide.
But i Wonder how can i access the user folder.
To all of you who are having problems with gcc:
-install xcode
I’m not sure if they ask you right away if you want to install the developer tools if they automatically or if you have to select it on your own, but just install them.
-then go to preferences>downloads>command line tools and install
gcc should work now
i have done as per instructed but it keeps popping back –> undefined symbols for architecture x86_64
yet i’m using c not c++
For those getting “gcc: command not found” try “cd /usr/bin” first