-include
标志(https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html)始终包含配置标头。
配置标头设置了标头文件所需的许多#定义,即启用/禁用某些API。
配置标头如下所示:
#ifndef CONFIG_H_
#define CONFIG_H_
// part of library, defines some stuff to use in this file
#include "config_defs.h"
<#define several config settings>
// also part of library, has a defaults via `#ifndef`->`#define`
#include "config_defaults.h"
#endif // CONFIG_H_
遗憾的是,不能将该标头添加到每个文件。
由于设置的数量,我希望避免将完整的配置和所有默认设置转换为-D
(即通过defines = [...]
)。
从外观上看,配置需要在CcToolchainConfigInfo.includes
(https://docs.bazel.build/versions/master/cc-toolchain-config-reference.html#cctoolchainconfiginfo-build-variables)中结束,但我不知道如何将其放到那里。
我尝试在工具链中添加-include
(通过功能标志),但不知道如何告诉它挂载文件。
选项:
添加--定义到.bazelrc:build --define VAR1=hello
build --define VAR2=world
定义将包装默认cc_库的宏:
def my_cc_library(
name,
copts=[],
**kwargs):
cc_library(
name = name,
copts = copts + ["-DVAR=1"],
**kwargs)
我推荐第二个选项。
上一篇:将nlohmann/json构建为Bazel库不会带来任何需要构建的错误错误、nlohmann、json、Bazel
下一篇:当使用CultureInfo.GetCultureInfo(字符串)或CultureInfo.CreateSpecificCulture(字符串)字符串、CultureInfo、GetCultureI