【问题标题】:can not build cpp using clang pre-built binary: file wchar.h not found无法使用 clang 预构建的二进制文件构建 cpp:找不到文件 wchar.h
【发布时间】:2020-08-02 00:40:58
【问题描述】:

我使用的是 MacOS 10.15。由于 MacOS 附带的 clang 不包括 clang-format。我从here 安装了另一个预先构建的clang 二进制文件。我已将二进制文件路径添加到我的 PATH 变量中。

export PATH="$HOME/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin:$PATH"

我尝试编译一个简单的程序:

#include <iostream>

int main(int argc, char *argv[]) {
    std::cout << "Hello world!\n";
    return 0;
}

使用以下命令:

clang++ hello.cpp -o hello

我收到以下错误:

In file included from hello.cpp:1:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/iostream:37:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/ios:214:
In file included from /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/iosfwd:95:
/Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/bin/../include/c++/v1/wchar.h:118:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

我发现与这个预构建包捆绑在一起的wchar.h位于以下目录中:

/Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/include/c++/v1/

所以我添加了-I 标志:

clang++ -I /Users/jdhao/tools/clang+llvm-10.0.0-x86_64-apple-darwin/include/c++/v1 hello.cpp -o hello 

错误仍然存​​在。

如果我使用 MacOS 自带的clang++,编译源代码没有问题:

# the following works without any error
/usr/bin/clang++ hello.cpp -o hello

我看过hereherehere的帖子,但解决方案不适用。

【问题讨论】:

    标签: c++ macos clang clang++ llvm-clang


    【解决方案1】:

    你得到了不正确的clang-format。将系统重置为安装另一个预构建的 clang 二进制文件之前的状态。然后使用 Homebrew 安装 clang-format

    brew install clang-format
    

    clang+llvm-10.0.0-x86_64-apple-darwin 不适合您的 Mac。这取决于不可用的系统框架,因此您会在系统框架中找到wchar.h 的错误。当您安装 clang+llvm-10.0.0-x86_64-apple-darwin 时,您会忽略框架依赖项。 Homebrew 会关心依赖关系。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      • 2015-02-14
      • 2018-07-22
      相关资源
      最近更新 更多