Run C and C++ on terminal with Xcode

Well, I installed last version of Xcode on MacOs Mojave and It can not run programs in C and/or C++ using terminal. The fatal error is:

In file included from main.cp:1:0:

/usr/local/include/c++/7.1.0/cstdio:42:10: fatal error: stdio.h: No such file or directory

#include <stdio.h>


I've already unistalled/reinstalled Xcode, I've put old versions but I could not solve it.


Can someone help me?


Thanks


Rodolfo

Replies

Xcode doesn't put anything into /usr/local. You have some kind of funky, custom setup. Also, <stdio.h> in C++ hasn't been used for close to 20 years.

If you install Xcode in the usual place then you should be able to compile C++ programs from the command line in the usual way. First, make sure that the system knows where your Xcode is. You can do that using

xcode-select
:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

Next, create a C++ program in the way you’d do on any other UNIX-based system:

$ cat hello.cpp 
#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello Cruel World!\n";
    return 0;
}
$ c++ hello.cpp 
$ ./a.out
Hello Cruel World!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"