简体   繁体   English

clang ++:致命错误:'unistd.h'文件未找到

[英]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. 使用OS X 10.10.2,我下载了适用于Mac OS X v.3.6.0的Clang ,并尝试编译一个简单的Hello World程序。

The commands I use are these: 我使用的命令是:
(assumes you downloaded clang to . ) (假设你下载了clang .

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 这是有道理的,因为没有文件unistd.h ,可以通过验证

find . -name unistd.h

which yields 0 results. 产生0结果。

I tried downloading the LibC++ source code v. 3.6.0 but even that contains no unistd.h . 我尝试下载LibC ++源代码 v.3.6.0,但即使它不包含unistd.h Where can I find the official/vanilla version of that file, and the files that are referenced, and meta-referenced, by it? 我在哪里可以找到该文件的官方/ vanilla版本,以及由它引用和元引用的文件?

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. Clang不包括交流库或系统头,如果你想在OS X上编程,你需要安装Xcode。如果你不想安装整个Xcode包, 这个页面有更多的细节,你可以逃脱仅限命令行工具。

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. 一旦你安装了Xcode /命令行工具,你可以使用Xcode或你下载的那个版本的clang和gcc,尽管如果你想使用最新版本的任何一个,通常更容易使用MacportsHomebrew

That error disappeared after running xcode-select --install . 运行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.) (我只保留HomeBrew的LLVM和clang定期更新,所以我的原始macos标题必须是古老的/不存在的,直到我使用上面的命令来修复它。)

unistd.h is not a C or a C++ header! unistd.h不是C或C ++标题! It is a POSIX header. 它是一个POSIX标题。

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. 您可以安装XCode,因为它来自那里,但老实说我不知道​​这是否完全与Clang运行时兼容。 I'm not a Mac person. 我不是Mac人。

Perhaps you can find an alternative; 也许你可以找到另一种选择; for example, there's no way you need unistd.h to compile a "Hello world" program! 例如, 你不可能需要unistd.h来编译一个“Hello world”程序!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Clang 错误 - 致命错误:找不到“unistd.h”文件 - Clang error - fatal error: 'unistd.h' file not found 在 Clang++ 中定位 iostream:致命错误:找不到“iostream”文件 - Locating iostream in Clang++: fatal error: 'iostream' file not found 无法打开包含文件:“unistd.h”:没有这样的文件或目录 - Cannot open include file: 'unistd.h': No such file or directory unistd.h 中的 pwrite() 未将数据写入 C++ 中的文件 - pwrite() from unistd.h is not writing data to file in C++ Header 文件未找到错误:<conio.h> 和<process.h>在 macOS Catalina 中的 VScode Cmake 或 Clang++ 中编译时</process.h></conio.h> - Header file not found Error: <conio.h> and <process.h> while compiling in VScode Cmake or Clang++ in macOS Catalina 是否有适用于 Windows (Visual C) 的 unistd.h 的替代品? - Is there a replacement for unistd.h for Windows (Visual C)? 关于unistd.h(C ++)中的read() - About the read() in unistd.h (C++) 有没有人在Ubuntu上找不到unistd.h的情况? - Anyone ever have a case where unistd.h cannot be found on Ubuntu? GMOCK Clang 讨厌的错误“/usr/include/limits.h:123:16: 致命错误: 'limits.h' 文件未找到” - GMOCK Clang pesky error "/usr/include/limits.h:123:16: fatal error: 'limits.h' file not found" 为 Windows 实现自定义 unistd.h 以在 Visual Studio 上工作 - 问题 - Implementing a custom unistd.h for windows to work on Visual Studio - problems
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM