I'm trying to compile a simple C program on mac However I can't ever seem to get Xcode to work so I want something else. I also want to check the code for errors while I'm running it anyone got a good idea?
Asked
Active
Viewed 2,662 times
0
-
2XCode comes with the `gcc` and `gdb` command line tools which work (mostly) just like their Linux equivalents. Xcode is just a graphical front-end for those tools. – Sergey L. Mar 21 '13 at 13:30
1 Answers
5
open Terminal
, cd
to your source directory,
then type gcc -Wall yourProgram.c -o YourProgram
and if everything is good, you will be able to execute the program typing ./YourProgram
Also, if you are just learning C, then do not use IDEs just yet. get used to the terminal and as your experience builds, move to an IDE.]
Also there are tools like lint
that analyze your code statically. Use gdb and if available, use valgrind as well for runtime debugging. I am not sure if valgrind is available on mac. Have a look at dtrace
and how to use it.

Aniket Inge
- 25,375
- 5
- 50
- 78
-
Or stick with the command line forever, and ignore the IDE permanently. ;-) – Randy Howard Mar 21 '13 at 13:51
-
1@RandyHoward I bet he wants to learn IOS development later on. :-) He might like the IDE more then. Or maybe Cocoa development. – Aniket Inge Mar 21 '13 at 13:53
-
Xcode installation has changed; it may be necessary to install the command line tools, per [this answer](http://stackoverflow.com/a/9329325/298225). – Eric Postpischil Mar 21 '13 at 15:22