0

I am fairly new to both MacOs and C++ and have a problem which is similar to the one described here but also no solution I find in the Internet works.

'fatal error: 'wchar.h' file not found' error with the new macos 11.3 update

If I try to compile the most simple c++ program on my machine via command line it does not work.


#include <iostream>
int main()
{
 std::cout << "Hello, World!" << std::endl;
 return 0;
}

Since it used to work I probably broke something but don't know what

The simple test command I use is the following

 clang -v --target=arm64   helloworld.cpp

Which results in a iostream not found error

if I now include the xcode include directory via

clang -v --target=arm64  -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ helloworld.cpp

The iostream error disappears and I get a wchar.h not found error

I removed xcode completely and reinstalled it but this seems to not help also does it not make a difference if I use clang or clang++.

With Clion and cmake it works but I do not know why

xcode-select version 2392

/usr/bin/clang

Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

locate iostream.h


`/Library/Frameworks/Mono.framework/Versions/6.12.0/include/glib-2.0/gio/gfileiostream.h
/Library/Frameworks/Mono.framework/Versions/6.12.0/include/glib-2.0/gio/giostream.h
/opt/homebrew/Cellar/boost/1.76.0/include/boost/asio/basic_socket_iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/iostreams/detail/iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/math/cstdfloat/cstdfloat_iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/nowide/iostream.hpp
/opt/homebrew/Cellar/boost/1.76.0/include/boost/typeof/std/iostream.hpp
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/gfileiostream.h
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/giostream.h
/opt/homebrew/Cellar/glib/2.70.2/include/glib-2.0/gio/gsimpleiostream.h
myfoxit
  • 69
  • 2
  • 8

1 Answers1

0

I had similar troubles building clang + llvm, then trying to use the newly built clang via

./build/bin/clang -std=c++20 <my_file>

gave me a

fatal error: 'iostream' file not found

What fixed it was if I compiled with the following instead:

./build/bin/clang -std=c++20 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk <my_file>

The fix largely comes from https://github.com/MaskRay/ccls/issues/191#issuecomment-556983460 and the discussion there

ginginsha
  • 142
  • 1
  • 11