我想用clang而不是g来编译我的c文件,而g是系统的默认编译器 .
我试过了 sudo update-alternatives --install c++ c++ /home/guo/bin/clang++ 100
并设置了 CC
环境 . 但它们不起作用 . Bazel仍然使用g作为编译器 .
一小时后,Bazel使用了铿锵声 . 但是发生了错误 .
ERROR: /home/guo/utils/lib/BUILD:2:1: C++ compilation of rule '//utils/lib:get_pdf' failed: linux-sandbox failed: error executing command /home/guo/.cache/bazel/_bazel_guo/d2d93a82f24e8dc5485ac1b29928428e/execroot/_bin/linux-sandbox ... (remaining 41 argument(s) skipped).
src/main/tools/linux-sandbox-pid1.cc:592: "execvp(/home/guo/lib/clang, 0x23abde0)": Permission denied
Target //utils/lib:get_pdf failed to buildenter code here
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.159s, Critical Path: 0.06s
Ps: /home/guo/lib/clang
是一个目录,而不是我电脑中的二进制文件 . 我想这里应该是 /home/guo/bin/clang++
但我不知道怎么让 Bazel
知道它 .
Ps:您似乎需要在更改环境时重新启动 Bazel
服务器 .
1 回答
因此,为Bazel配置C工具链的正确方法是使用CROSSTOOL . 因为那是nontrivial endeavor,Bazel尝试使用cc_configure.bzl脚本自动检测您的工具链 . 此脚本检查一些环境变量,如果存在,它将使用那里的值 . 要配置gcc,您可以设置
CC
变量,Bazel将设置它(in _find_cc function) .在缓存这些结果时,运行
bazel clean --expunge
以刷新缓存并在下次重新运行自动配置 .