我目前正在努力使用clang ++,在网上浏览了很长时间之后我决定提出问题。我在OS X上并通过Emacs使用clang ++(flycheck使用它来突出显示错误等)。我有一个非常简单的文件,以:
开头#include <iostream>
该行用红色加下划线。当我去查看铿锵记录时,这就是我所拥有的:
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 ++),所以一切都很好。只是铿锵有力的++已经失去了。
我注意到的是它在我的llvm文件夹(我用自制软件安装)中获取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 ++标题上存在同样的问题。