4

I installed clang with Homebrew. If I try to compile a hello world program, I get this error:

In file included from hello.cpp:1:
In file included from /usr/local/opt/llvm/bin/../include/c++/v1/iostream:38:
In file included from /usr/local/opt/llvm/bin/../include/c++/v1/ios:215:
In file included from /usr/local/opt/llvm/bin/../include/c++/v1/iosfwd:96:
/usr/local/opt/llvm/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

Clang is able to find the bundled C++ standard library headers but not the C standard library headers. GCC-8 (also installed with Homebrew) is able to find the C standard library headers. I have Xcode installed and Apple Clang can find the C standard library headers too. Maybe this has something to do with the fact that LLVM is keg-only.

Is there a one-time fix for this so that I don't have to pass a path to every invocation of clang? Maybe this is a problem with the Homebrew formula?

halfer
  • 19,824
  • 17
  • 99
  • 186
Indiana Kernick
  • 5,041
  • 2
  • 20
  • 50
  • 1
    In C++, its as I see on cppreference. http://www.cplusplus.com/reference/cwchar/ – Hemil Mar 11 '19 at 04:23
  • @Hemil The error message I've shown is from **inside cwchar**. The C++ header #includes the C header but the problem is that the C header is not found. – Indiana Kernick Mar 11 '19 at 05:20
  • I don't have Mac OS but this code: `#include #include #include int main(){ wchar_t a[80], b[80]; wcscpy (a, L"Hello"); wcscpy (b, L" World"); std::wcout << wcscat(a, b) << "\n"; }` works fine on my Fedora 29 with clang 7.0.1 – Hemil Mar 11 '19 at 15:40
  • @Hemil My problem is not with clang. My problem is with clang installed with Homebrew on macOS. The fact that clang works elsewhere is irrelevant. – Indiana Kernick Mar 11 '19 at 16:59

0 Answers0