Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

compiling a c program

I've just started using xcode to write some programming in C. The only problem is that I have no idea how to compile the code in xCode. I've gone to build tab where "compile" is located, but it is greyed out. Am i doing something wrong?

Powermac G5 Dual Core 2.0 ●●● 3GB RAM, Mac OS X (10.4.6), Dual 19" Displays ●●● 1/2 Terabyte HD ●●● Bose Companion 3

Posted on Jun 15, 2006 11:04 AM

Reply
9 replies

Jun 16, 2006 12:54 PM in response to Christopher Varjas

I'm just starting to learn C and I'm making the
beginning Hello World! example. Now are my results
supposed to show up in Terminal?


You could launch the example from the Terminal, but you can also run it in Xcode. Choose Debug > Run Executable to run the program in Xcode. A run log window will open, which will show the results of the program.


Mac OS X (10.4)

Jun 20, 2006 8:51 PM in response to Christopher Varjas

So if I were to use terminal for the programs should
i just enter them the same as I would in XCode,
formatting and all?



Pretty much. You just need to make sure the files you save are plain text files. So you'd need a text editor that will save plain text files.

And is the "Hello World" message supposed to only
come up in terminal or should it be coming up in a
new window, like an alert type message?


Anything that's printed out will appear in the Terminal window. For example, here's a simple C program I typed into TextWrangler:

<pre class="command">#include <stdio.h>

int main (void)
{
printf("Hello World\n");
return 0;
}</pre>If I save that in a text file called helloworld.c, I can compile it like this from the Terminal (as long as I'm in the same directory):

<pre class="command">gcc -Wall -o helloworld helloworld.c</pre>To run it, I type this at the Terminal prompt:

<pre class="command">./helloworld</pre>And I get this on the next line:

<pre class="command">Hello World</pre>Once the program is done running, the command line prompt will show up again.

charlie

Jun 21, 2006 1:40 PM in response to Charles Minow

Very nice explanation.

I use TextWranger very often. However, there may be situations where you don't have a user interface available. MacOSX can be used entirely with the terminal. Just type "vi helloworld.c".

Oh, before you do that. Download one of the many "vi cheatsheets". TextWranger, BBEdit, etc. are very nice tools, but there are always alternatives.

compiling a c program

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.