C++ 在OSX上使用llvm/clang(来自brew)

C++ 在OSX上使用llvm/clang(来自brew),c++,macos,llvm,C++,Macos,Llvm,使用brew安装llvm安装llvm 我有一个简单的文件,如: int main() { std::cout << "Ain't this a fine pickle ?" << std::endl; } 我明白了: In file included from main.cpp:1: In file included from /usr/local/opt/llvm/include/c++/v1/iostream:38: In file included from

使用
brew安装llvm安装llvm

我有一个简单的文件,如:


int main() {
  std::cout << "Ain't this a fine pickle ?" << std::endl;
}
我明白了:

In file included from main.cpp:1:
In file included from /usr/local/opt/llvm/include/c++/v1/iostream:38:
In file included from /usr/local/opt/llvm/include/c++/v1/ios:215:
In file included from /usr/local/opt/llvm/include/c++/v1/iosfwd:90:
/usr/local/opt/llvm/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.
我可以看到指定包含路径的文件:

> $ l /usr/local/opt/llvm/include/c++/v1/wchar.h
-rw-r--r--  1 abrahma  staff   8.2K Dec  7 12:42 /usr/local/opt/llvm/include/c++/v1/wchar.h
最终起作用的是:

  • open/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
  • 按照提示安装软件包
  • 在此之后,您应该会看到
    /usr/include
    的出现
  • 现在从brew安装的
    clang++
    可以正常工作了

(归功于)

编译器通常在哪里找到
wchar.h
?尝试
echo“#包括”| g++-E-H-xc++-2>&1 | egrep'wchar\.H$”
。这可能会显示一些有用的内容。或者,您可以使用
-isysroot
标志,指向
xcrun--show sdk path
> $ echo '#include <wchar.h>' | /usr/local/opt/llvm/bin/clang++ -I/usr/local/opt/llvm/include -I/usr/local/opt/llvm/include/c++/v1 -L/usr/local/opt/llvm/lib -E -H -xc++ -
clang-7: warning: argument unused during compilation: '-L/usr/local/opt/llvm/lib' [-Wunused-command-line-argument]
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 399 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
# 1 "/usr/local/opt/llvm/include/c++/v1/wchar.h" 1 3
. /usr/local/opt/llvm/include/c++/v1/wchar.h
# 109 "/usr/local/opt/llvm/include/c++/v1/wchar.h" 3
# 1 "/usr/local/opt/llvm/include/c++/v1/__config" 1 3
.. /usr/local/opt/llvm/include/c++/v1/__config
# 22 "/usr/local/opt/llvm/include/c++/v1/__config" 3
# 475 "/usr/local/opt/llvm/include/c++/v1/__config" 3
namespace std {
  inline namespace __1 {
  }
}
# 110 "/usr/local/opt/llvm/include/c++/v1/wchar.h" 2 3
# 113 "/usr/local/opt/llvm/include/c++/v1/wchar.h" 3
In file included from <stdin>:1:
/usr/local/opt/llvm/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
# 135 "/usr/local/opt/llvm/include/c++/v1/wchar.h" 3
extern "C++" {
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
wchar_t* __libcpp_wcschr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcschr(__s, __c);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
      wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return __libcpp_wcschr(__s, __c);}

inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
wchar_t* __libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcspbrk(__s1, __s2);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
const wchar_t* wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
      wchar_t* wcspbrk( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcspbrk(__s1, __s2);}

inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
wchar_t* __libcpp_wcsrchr(const wchar_t* __s, wchar_t __c) {return (wchar_t*)wcsrchr(__s, __c);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
const wchar_t* wcsrchr(const wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
      wchar_t* wcsrchr( wchar_t* __s, wchar_t __c) {return __libcpp_wcsrchr(__s, __c);}

inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
wchar_t* __libcpp_wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return (wchar_t*)wcsstr(__s1, __s2);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
const wchar_t* wcsstr(const wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
      wchar_t* wcsstr( wchar_t* __s1, const wchar_t* __s2) {return __libcpp_wcsstr(__s1, __s2);}

inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
wchar_t* __libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return (wchar_t*)wmemchr(__s, __c, __n);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__)) __attribute__ ((__enable_if__(true, "")))
      wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return __libcpp_wmemchr(__s, __c, __n);}
}
# 2 "<stdin>" 2

1 error generated.
> $ l /usr/local/opt/llvm/include/c++/v1/wchar.h
-rw-r--r--  1 abrahma  staff   8.2K Dec  7 12:42 /usr/local/opt/llvm/include/c++/v1/wchar.h