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.
Related
I have just installed the latest stable version of wxWidget on my mac and tried to compile the code from the hello world tutorial. This is the code that is causing the error:
#include <wx/wxprec.h>'
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
My compiler throws the following warning:
hello_world.cpp:4:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
^~~~~~~~~~~~~
1 error generated.
I have checked the directory where I installed wxMac and the file wxprec.h exists in the "include" sub-directory.
If anyone knows why the file cannot be found even though it exists please let me know.
I found out the answer to this problem. To fix it I used the following line to compile/build the hello world app:
g++ `wx-config --cxxflags` -o out *.cpp `wx-config --libs`
after doing this it was only a matter of sorting out the linking, adding header guards and adding in
IMPLEMENT_APP(MyApp)
and
DECLARE_APP(MyApp)
in MyApp.h and MyApp.cpp respectively which functions as the main function.
I got this information from https://wiki.wxwidgets.org/Hello_World
I have a 16inch MacBook pro with latest updates (macOS Catalina 10.15.2 (19C57)), the latest version of XCode and Command line tools for macOS (the tools being installed in the usual path /Library/Developer/CommandLineTools/).. Not sure if this is relevant to my issue or not, but I also have the latest version of JetBrains’s CLion installed on my machine (running without issues).
Here is the problem: When trying to build a project with cmake, the build FAILS, giving me this error message:
In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootDFile.cc:25:
In file included from /Users/basavyr/Pipeline/DevWorkspace/Github/xrootd/bindings/python/src/PyXRootD.hh:28:
In file included from /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:38:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error:
'string.h' file not found
#include_next <string.h>
1 error generated.
error: command '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc' failed with exit status 1
make[2]: *** [bindings/python/python_bindings] Error 1
make[1]: *** [bindings/python/CMakeFiles/python_target.dir/all] Error 2
make: *** [all] Error 2
and this is probably related to my C++ compiler not having the correct path to the include files. To see what the issue could be, I’ve made a simple C++ file and I tried to compile it.
main.cpp
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
int main()
{
std::string name = "NAMEX";
std::cout << name;
}
First, I tried with the usual “g++” and it worked just fine:
basavyr#Roberts-MacBook-Pro stringTestCLANG % g++ main.cpp
basavyr#Roberts-MacBook-Pro stringTestCLANG % ./a.out
NAMEX% basavyr#Roberts-MacBook-Pro stringTestCLANG %
Then, I tried with /Applications/Xcode.app/Contents/Developer/usr/bin/g++ main.cpp and it worked just fine.
Checking the version of “g++” on my machine gives me this:
g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
This is interesting, because I was expecting that the default compiler is installed in /usr/bin/ instead. Going into that “InstalledDir” folder I saw that there is no “g++” binary, but only “clang++” and “c++”, so I tried to compile with both and it turns out that both compilers are giving the same error as the one in the project that I trying to build:
basavyr#Roberts-MacBook-Pro stringTestCLANG % /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ main.cpp
In file included from main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:505:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string_view:176:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string.h:61:15: fatal error:
'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
basavyr#Roberts-MacBook-Pro stringTestCLANG %
Since I also have Command Line Tools installed, I tried to compile with both “g++” and “clang++” from /Library/Developer/CommandLineTools/usr/bin/ and the first one compiles successfully, while the second one throws the same error with regards to the string header file.
basavyr#Roberts-MacBook-Pro stringTestCLANG % /Library/Developer/CommandLineTools/usr/bin/c++ main.cpp
In file included from main.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string:505:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string_view:176:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__string:57:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:642:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cstring:61:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/string.h:61:15: fatal error: 'string.h' file not found
#include_next <string.h>
^~~~~~~~~~
1 error generated.
So, I assume that when I build that project with cmake, it is using one of these compilers (from the XCodeDefault.xctoolchain folder) and it has issues with the string header.
Q1: How can I solve this issue? Q2: And also, why does my “g++” installation directory points to this XCodeDefault.xctoolchain instead of “/usr/bin/’ or “/Applications/Xcode.app/Contents/Developer/usr/bin/”. Is there a way to change that in macOS?
Thank you in advance
Currently I am trying to compile a llvm C++ file including the following header file:
#include <clang-c/Index.h>
and I have made sure that clang-c/Index.h does exist in /usr/local/include/clang-c/Index.h, but when I try to compile it with
clang++ main.cpp
the compile says
fatal error: 'clang-c/Platform.h' file not found
Any help would be appreciated!
I am trying to compile a piece of open source software called "SPECIES
Identification of Taxonomic Mentions in Text". I am on MacOS.
I downloaded the source code (which can be found here), moved into the directory and used the command make to compile. This is the error returned:
g++ -fpic -pthread -Wall -O3 -o organisms organisms.cxx -lm -lboost_regex
In file included from batch_tagger.h:5:0,
from organisms.cxx:3:
tagger.h:7:27: fatal error: boost/regex.hpp: No such file or directory
compilation terminated.
make: *** [organisms] Error 1
I installed the C++ boost library using brew install boostand tried the above steps again (it did not work).
I tried dropping the boost directory into the directory containing the source code (it did not work).
Any suggestions/help?
You need to tell the compiler where to find boost headers.
You need to use the include path option to specify where the boost headers can be find, use -I/path/to/boost/include.
Then include the file using #include <boost/regex.hpp> from your code.
I am trying to build the PrintFunctionNames example from clang.
However I get the following error:
[mac-osx:clang/examples/PrintFunctionNames] osx% clang++ -std=c++0x PrintFunctionNames.cpp
In file included from PrintFunctionNames.cpp:15:
In file included from /usr/local/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from /usr/local/include/clang/Frontend/FrontendAction.h:22:
In file included from /usr/local/include/clang/Basic/LLVM.h:22:
In file included from /usr/local/include/llvm/Support/Casting.h:19:
/usr/local/include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
System Info:
clang version 4.0.0 (http://llvm.org/git/clang.git 6197d01def79876e2c1670ced871e10b12c36241) (http://llvm.org/git/llvm.git 24f7cd87f70ddcc91d50f77e405420c0c27853fd)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /usr/local/bin
OSX 10.11.6
Edit 1:
on making the changes suggested by Alex, I start getting header issues. On fixing it via includes, same error is thrown again
% clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I../../../clang/include -I../../../../include -I../../../../../build/include
In file included from PrintFunctionNames.cpp:15:
In file included from ../../../clang/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from ../../../clang/include/clang/Frontend/FrontendAction.h:22:
In file included from ../../../clang/include/clang/Basic/LLVM.h:22:
In file included from ../../../../include/llvm/Support/Casting.h:19:
../../../../include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
^
1 error generated.
OS X (macOS) has a bit different approach. You can have several Xcode installed and you compile for different platforms.
You should use -isysroot option to explicitly specify against which SDK to build.
The following command should do the trick
clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk
Otherwise, please check which SDKs are installed and change the value of isysroot to correspond to your setup.