I'm currently struggling with clang++, and after looking on the web for a long time I decided asking my question. I'm on OS X and using clang++ via Emacs (it's used by flycheck to highlight errors, among other things). I have a very simple file that starts with :
#include <iostream>
And the line is underlined in red. When I go check the clang logs, here's what I have :
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>
So, the error comes from the iostream
include, and in iostream
there's a #include <unistd.h>
that clang++ doesn't like.
I'll say it immediately, I have Xcode AND the command-line tools installed. So my unistd.h
should be there. My code also compiles (via g++), so everything is fine there. It's just clang++ that's lost.
Something I notice is that it's going in my llvm folder (that I installed with homebrew) to fetch iostream
, that doesn't seem right. He should be getting the iostream
in my system, right ? So /usr/local/include/c++/iostream
. Could this be the problem ? If so, how can I tell it to get the right iostream
?
And if it's not the problem, how could I solve my unistd.h
problem ?
Thanks in advance !
EDIT : With the clang++ -stdlib=libc++ image.cpp
command, I get this :
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.`
So, same problem.
EDIT 2 : I noticed which clang++
would return /usr/local/bin/clang++
, so I tried specifically using the Xcode clang++ and here's the result :
/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.
So same problem on the C++ headers bundled with XCode.