使用Bazel构建时如何设置C ++标准版本? [英] How to set C++ standard version when build with Bazel?
问题描述
我是C ++的新手.我知道如何使用CMake设置C ++版本,但不知道如何在Bazel中设置C ++版本.
I'm kinda new to C++. I know how to set C++ version with CMake, but don't know how to set C++ version in Bazel.
也许可以在cc_libary
中使用copts
参数进行设置,但是我必须在每个cc_libary
中进行设置?
Maybe set with the copts
parameter in cc_libary
but I have to set this in every cc_libary
?
推荐答案
要使用Bazel中的默认C ++工具链设置标准,您可以设置环境变量BAZEL_CXXOPTS
,例如BAZEL_CXXOPTS="-std=c++14"
.您也可以从命令行或使用--repo_env=BAZEL_CXXOPTS
在.bazelrc
中进行设置. :
是标志分隔符.
To set the standard using the default C++ toolchain in Bazel you can set environment variable BAZEL_CXXOPTS
, e.g. BAZEL_CXXOPTS="-std=c++14"
. You can also set it from the command line or from .bazelrc
using --repo_env=BAZEL_CXXOPTS
. :
is the flag separator.
或者,您也可以将--cxxopt
传递给Bazel,或将其放入.bazelrc
中,例如--cxxopt='-std=c++11'
.
Alternatively you can pass --cxxopt
to Bazel, or put it into .bazelrc
, e.g. --cxxopt='-std=c++11'
.
在Bazel中指定C ++工具链的可靠解决方案是使用CcToolchainConfigInfo
.请参阅 https://docs.bazel.build/版本/master/tutorial/cc-toolchain-config.html 和
The robust solution to specifying C++ toolchain in Bazel is to use the CcToolchainConfigInfo
. See the documentation at https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html and https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html.
这篇关于使用Bazel构建时如何设置C ++标准版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!