Unistd.h file not found, clang ++ and OS X

I am currently struggling with clang ++, and, looking at the Internet for a long time, I decided to ask my question. I am on OS X and use clang ++ through Emacs (it is used by flycheck to detect 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 to check clang logs, here is 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 arises from iostreaminclude, and in iostreamthere a #include <unistd.h>, that clang ++ does not like.

I will say it immediately, I have Xcode and command line tools. So mine unistd.hshould be there. My code also compiles (via g ++), so everything is fine. This is just clang ++ that is lost.

Something I notice is that it goes into my llvm folder (which I installed with homebrew) to get iostreamwhat doesn't seem right. It should get iostreamin my system, right? So /usr/local/include/c++/iostream. Could this be a problem? If so, how can I say to get the right one iostream?

And if this is not a problem, how can I solve my problem unistd.h?

Thanks in advance!

EDIT : with the command, clang++ -stdlib=libc++ image.cppI get the following:

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 the same problem.

EDIT 2 : I noticed that it which clang++would return /usr/local/bin/clang++, so I specifically tried using Xcode clang ++ and here is 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.

Same issue for C ++ headers related to Xcode.

+4

Source: https://habr.com/ru/post/1616453/


All Articles