简体   繁体   中英

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

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?

Clang does not include ac 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.

That error disappeared after running xcode-select --install .

(I only keep HomeBrew's LLVM and clang regularly updated, so my original macos headers must have been ancient/non-existent until I used the above command to fix that.)

unistd.h is not a C or a C++ header! It is a POSIX header.

You could install XCode as it'll come from that, but I honestly don't know whether that'll be at all compatible with the Clang runtime. I'm not a Mac person.

Perhaps you can find an alternative; for example, there's no way you need unistd.h to compile a "Hello world" program!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM