一些command line的笔记
clang -S -emit-llvm test.cpp -o test.ll -o0 在使用这个clang命令行是遇到了问题:
test.cpp:1:10: fatal error: 'stdio.h' file not found 1 | #include <stdio.h> | ^~~~~~~~~ 1 error generated.
clang没有找到stdio.h库相关的文件。
会不会是stdio.h没有安装?用的MacOS, stdio.h应该在Xcode工具里
运行 xcode-select --print-path,得到 /Library/Developer/CommandLineTools, 说明已经安装了Xcode工具
所以是clang没有找到这个头文件。这里用clang -v 打印clang默认寻找的根目录:运行 clang -v
得到
clang version 17.0.6
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /usr/local/bin
说明clang寻找的目录是/usr/local/bin 而不是MacOS里的/Library/Developer/CommandLineTools
所以改变寻找的系统根目录:加上 -isysroot $(xcrun --show-sdk-path), 运行 clang -S -emit-llvm test.cpp -o test.ll -O0 -isysroot $(xcrun --show-sdk-path) 成功了。
设置别名方便之后使用:alias clang="clang -isysroot $(xcrun --show-sdk-path)"