Max*_*and 5 c++ emacs header unistd.h clang++
我目前正在与 clang++ 作斗争,在网上查看了很长时间后,我决定提出我的问题。我在 OS X 上并通过 Emacs 使用 clang++ (flycheck 使用它来突出显示错误等)。我有一个非常简单的文件,以以下内容开头:
#include <iostream>
Run Code Online (Sandbox Code Playgroud)
该线用红色下划线表示。当我检查 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>
Run Code Online (Sandbox Code Playgroud)
所以,错误来自于iostreaminclude,并且其中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.`
Run Code Online (Sandbox Code Playgroud)
所以,同样的问题。
编辑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.
Run Code Online (Sandbox Code Playgroud)
与 XCode 捆绑在一起的 C++ 标头也存在同样的问题。