我正在使用MacOS 10.15。由于MacOS随附的叮当声不包含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
您没有正确获得clang-format
。在安装另一个预制的clang二进制文件之前,将系统重置为状态。然后使用Homebrew安装clang格式
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时,您将忽略框架依赖性。自制软件将关心依赖项。