XCode as C compiler

I have been trying to learn C in my new mini but i dont know how to use xcode as a c compiler. Can somebody help? I have it installed in my mac.

Mac Mini, Mac OS X (10.6.4)

Posted on Sep 1, 2010 3:49 AM

Reply
18 replies

Sep 1, 2010 4:54 AM in response to KKAFFES

Hi there,

After launching Xcode create a new project, select Application under Mac OS X from the new project window, select Command Line Tool. If the type isn't already C then select it from the list. Now select the Choose... button, you will be presented with a dialog box where you can select where to save your project.

Once you've done the above you will be presented with all the tools for creating your program. To bring up the console window and debugger select them from the Run menu.

To add arguments click the drop down arrow for Executables in Groups and Files, then get info for the executable in the list. Select arguments from the info window and add them by clicking the plus button underneath the Argument section.

J.C

Sep 1, 2010 7:49 AM in response to J D McIninch

It still doesn't print "Kostis" in the console. What should i blame? It prints:
[Session started at 2010-09-01 17:45:27 +0300.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys019
Loading program into debugger…
Program loaded.
run
[Switching to process 19209]

Sep 1, 2010 8:45 AM in response to KKAFFES

The output should look like this:

[Session started at 2010-09-01 05:38:57 -1000.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 534]
Running…
Kostis
Debugger stopped.
Program exited with status value:0.

Note the 'Running...'. Are you getting any related error messages in Applications>Utilities>Console?

BTW, the fflush is not required.

Message was edited by: xnav

Sep 1, 2010 3:31 PM in response to KKAFFES

I'll assume your program name is 'hello'. In Xcode right click on the program name 'hello' under 'Executables' in the 'Groups & Files' column, then select 'Get Info'. You should see the 'Full Path' name under the 'General' tab. Copy it except for the 'hello' and paste it into a Terminal window after typing 'cd'. As follows:

Path:~$cd /Users/YouUserID/XcodeProjects/Testc/build/Debug
Path:~/XcodeProjects/Testc/build/Debug$./hello
KostisPath:~/XcodeProjects/Testc/build/Debug$

'./hello' should execute the program. Note above, 'Kostis' appears on the same line as the next prompt line because you did not printf with a newline (" "). Do the above and see if an error results.

Sep 1, 2010 3:42 PM in response to KKAFFES

Here is an alternative, if you don't want to use the Xcode environment at all: use TextWrangler.

TextWrangler is a simple plain code editor (well... compared to Xcode), and I use it all the time to write plain C programs with. TextWrangler can compile and run your C program, and put its output into a new text window. All it needs is this piece of magic before the very first line of your actual C code:

#!/bin/sh
/usr/bin/gcc -xc - <<EVILEOF


and this at the very end of your file, starting on a new line:


EVILEOF
./a.out


I assigned a keyboard shortcut to the "Run" command, so for me it's a simple edit-compile and run-review result-edit loop.

I don't have a clue how it works 🙂 I got it from this 3-year-old post and have been a happy coder since!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

XCode as C compiler

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