4

我目前正在与clang ++作斗争,在网上看了很长时间后,我决定问我的问题。我在 OS X 上并通过 Emacs 使用 clang++(flycheck 使用它来突出显示错误等)。我有一个非常简单的文件,开头为:

#include <iostream>

这条线用红色下划线。当我去检查 clang 日志时,这就是我所拥有的:

In file included from ./point.hpp:4:
In file included from /usr/local/Cellar/llvm/3.6.2/bin/../include/c++/v1/iostream:37:
/usr/local/Cellar/llvm/3.6.2/bin/../include/c++/v1/__config:23:10: fatal error: 'unistd.h' file not found
#include <unistd.h>

所以,错误来自iostream包含,并且iostream有一个#include <unistd.h>clang++ 不喜欢的。

我会马上说,我已经安装了 Xcode 和命令行工具。所以我的unistd.h应该在那里。我的代码也可以编译(通过 g++),所以一切都很好。只是 clang++ 丢失了。

我注意到它在我的 llvm 文件夹(我用自制软件安装)中进行 fetch iostream,这似乎不正确。他应该进入iostream我的系统,对吧?所以/usr/local/include/c++/iostream。这可能是问题吗?如果是这样,我怎么能告诉它正确iostream

如果这不是问题,我该如何解决我的unistd.h问题?

提前致谢 !

编辑:使用clang++ -stdlib=libc++ image.cpp命令,我得到这个:

clang++ -stdlib=libc++ image.cpp
In file included from image.cpp:1:
In file included from ./image.hpp:4:
In file included from ./figure.hpp:4:
In file included from ./point.hpp:4:
In file included from /usr/local/Cellar/llvm/3.6.2/bin/../include/c++/v1/iostream:37:
/usr/local/Cellar/llvm/3.6.2/bin/../include/c++/v1/__config:23:10: fatal error: 'unistd.h' file not found
#include <unistd.h>
         ^
1 error generated.`

所以,同样的问题。

编辑 2:我注意到which clang++会返回/usr/local/bin/clang++,所以我专门尝试使用 Xcode clang++,结果如下:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -stdlib=libc++ image.cpp
In file included from image.cpp:1:
In file included from ./image.hpp:4:
In file included from ./figure.hpp:4:
In file included from ./point.hpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:37:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:23:10: fatal error: 'unistd.h' file
  not found
#include <unistd.h>
         ^
1 error generated.

所以与 XCode 捆绑的 C++ 头文件也存在同样的问题。

4

0 回答 0