How do I compile a c program from my Mac terminal?

Hi,

I'm a new programmer. I have written a c++ program on my mac terminal and I can't run it. I'm using a MacBook Pro 2014 with OS X Yosemite. I have x code installed as well. I've also got emacs installed. So I'm having troubles compiling and executing the program.

MacBook Pro (Retina, 13-inch, Mid 2014), OS X Yosemite (10.10.1)

Posted on May 16, 2015 3:07 PM

Reply
4 replies

May 16, 2015 5:23 PM in response to Undergroundkinng

What problem(s) are you having? There is no way to tell from your post if you can't find the compiler or if the complier is failing or your program is compiling eh errors or fails when you run it.


You need to supply information in order to get a question answered.


In the meantime as a quick guess are you sure you have the command line tools installed? There are not a part of Xcode and need to be installed separately.

May 18, 2015 9:09 AM in response to Undergroundkinng

Unless you have munged your default PATH parameters, the command line tool compilers are all located in /usr/bin.


They are:

  • g++ (Apple's, based on Clang)
  • clang++
  • llvm-g++ (link to clang++)
  • c++ (link to clang++)


These will automatically search for the default libstd++, or libc++ (c++-11) shared libraries, and are invoked in the Terminal as:


clang++ -O2 -o mycode mycode.cpp

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.

How do I compile a c program from my Mac terminal?

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