【发布时间】: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
【问题讨论】:
标签: c++ macos clang clang++ llvm-clang