一些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)"

全部评论

相关推荐

06-12 10:50
门头沟学院 Java
你的不定积分没加C:我怎么在学院群看到了同样的话
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务