tensorflow/stream_executor/platform/platform.h
定义了一些宏。 TF如何设置诸如ANDROID
,__ANDROID__
,PLATFORM_GOOGLE
,RASPBERRY_PI
的宏?
我认为bazel BUILD文件可能会预置一些宏,例如cmake(Define preprocessor macro through cmake),但是我找不到任何线索。
最佳答案
看一下.bazelrc文件。例如,它定义build:android_arm --config=android
。这意味着您可以使用bazel build --config=android
在bazel中进行构建-我猜是带有目标android的编译器在系统 header 中提供ANDROID
和__ANDROID__
定义-因此您不必显式修改cc_binary
目标。
您还可以将定义显式添加到cc_binary
:cc_binary
目标提供define
和copts
属性:
cc_binary(name, deps, srcs, data, args, compatible_with, copts, defines, deprecation, distribs, exec_compatible_with, features, includes, licenses, linkopts, linkshared, linkstatic, malloc, nocopts, output_licenses, restricted_to, stamp, tags, testonly, toolchains, visibility, win_def_file)
从documentation:
defines:
List of strings; optional
List of defines to add to the compile line. Subject to "Make" variable substitution and Bourne shell tokenization. Each string, which must consist of a single Bourne shell token, is prepended with
-D
(or/D
on Windows) and added toCOPTS
. Unlikecopts
, these flags are added for the target and every rule that depends on it! Be very careful, since this may have far-reaching effects. When in doubt, add "-D" (or /D on Windows) flags tocopts
instead.
我建议您将定义添加到
copts
属性,例如:cc_binary(
srcs = ["main.cpp"],
copts = ["-DMY_DEFINE"],
)
关于c++ - Tensorflow如何定义预处理器宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408149/