让llvm / clang(来自brew)在OSX上运行

时间:2019-02-12 18:27:27

标签: c++ macos llvm

使用brew install llvm

安装了llvm

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


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

我正在跑步:

/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 main.cpp

我看到:

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.

有什么线索吗?

编辑:我尝试运行sudo xcode-select --switch /Library/Developer/CommandLineTools/,因为在其他地方已经提到过,但是它没有任何改变。

编辑:根据建议,尝试获取有关头文件位置的信息:

> $ 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

1 个答案:

答案 0 :(得分:0)

最终有效的方法:

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

(贷记this note