Saturday, 11 August 2018

How To Run C Program On Mac

Run C Program on Mac

Create a program first in a file.
#include <stdio.h>

int main(void)    
{
  printf("Hello, world!\n");
  return 0;
}
save your program as program.c.
Now we will need a compiler, go to App Store and install Xcode which is Apple's compiler and development tools. 
To find App Store? Search in "Spotlight Search" by typing Space and start typing App Store and hit Enter when it guesses correctly.
Xcode looks like this on App Store:
enter image description here
Then you need to install the command-line tools in Terminal. To open terminal type "terminal" in "Spotlight Search" 
xcode-select --install
Now compile the code by  running gcc as in the next line:
gcc -Wall -o program program.c
Note: On newer versions of OS X, you would use clang instead of gcc, like this:
clang program.c -o program
Then you can run it with:
./program
Hello, world!

If your program is C++, you'll probably want to use one of these commands:
clang++ -o program program.cpp
g++ -std=c++11 -o program program.cpp
g++-7 -std=c++11 -o program program.cpp

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel