我想用clang ++代替g ++来编译我的c ++文件,而g ++是系统的默认编译器.
我试过sudo update-alternatives --install c++ c++ /home/guo/bin/clang++ 100并设置了CC环境.但它们不起作用.Bazel仍然使用g ++作为编译器.
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
Run Code Online (Sandbox Code Playgroud)
Ps:/home/guo/lib/clang是一个目录,而不是我电脑中的二进制文件.我想这应该是,/home/guo/bin/clang++但我不知道如何让它Bazel知道.
Bazel在更改环境时重新启动服务器.
因此,为Bazel配置C ++工具链的正确方法是使用CROSSTOOL。由于这是不平凡的工作,因此Bazel尝试使用cc_configure.bzl脚本自动检测您的工具链。该脚本检查一些环境变量,如果存在,它将使用那里的值。要配置gcc,您可以设置CC变量,Bazel将使用它(在_find_cc函数中)。
缓存这些结果后,请运行bazel clean --expunge以刷新缓存并在下次重新运行自动配置。