clang++: fatal error: 'unistd.h' file not found

user4664340 picture user4664340 · Mar 31, 2015 · Viewed 19.5k times · Source

Using OS X 10.10.2, I download Clang for Mac OS X v. 3.6.0, and try to compile a simple Hello World program.

The commands I use are these:
(assumes you downloaded clang to .)

cd .
./clang+llvm-3.6.0-x86_64-apple-darwin/bin/clang++ main.cpp

The result is this:

In file included from main.cpp:1:
In file included from ./clang+llvm-3.6.0-x86_64-apple-darwin/bin/../include/c++/v1/iostream:37:
./clang+llvm-3.6.0-x86_64-apple-darwin/bin/../include/c++/v1/__config:23:10: fatal error: 'unistd.h' file not
  found

which makes sense, as there is no file unistd.h, as verifiable by

find . -name unistd.h

which yields 0 results.

I tried downloading the LibC++ source code v. 3.6.0 but even that contains no unistd.h. Where can I find the official/vanilla version of that file, and the files that are referenced, and meta-referenced, by it?

Answer

user657267 picture user657267 · Mar 31, 2015

Clang does not include a c library or system headers, you'll need to install Xcode if you want to program on OS X. This page has some more details if you don't want to install the entire Xcode package, you can get away with the command line tools only.

Once you have Xcode / command line tools installed you can either use the versions of clang and gcc included with Xcode or the one you downloaded, although it's usually easier to use Macports or Homebrew if you're looking to use up to date versions of either.