c++ - Tensorflow如何定义预处理器宏?

标签 c++ tensorflow macros bazel

tensorflow/stream_executor/platform/platform.h 定义了一些宏。 TF如何设置诸如ANDROID__ANDROID__PLATFORM_GOOGLERASPBERRY_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目标提供definecopts属性:

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 to COPTS. Unlike copts, 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 to copts instead.



我建议您将定义添加到copts属性,例如:
cc_binary(
    srcs = ["main.cpp"],
    copts =  ["-DMY_DEFINE"],
)

关于c++ - Tensorflow如何定义预处理器宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408149/

相关文章:

python - gensim Doc2Vec vs tensorflow Doc2Vec

c - 无法使用 ifdef 宏初始化结构内部的数组

ios - 这个Mac SDK可以在iOS应用程序中运行吗?

c++ - 在我的 C++ OpenFrameworks 项目中未定义对 wpa_ctrl 函数的引用。需要帮助集成这个 c 库

c++ - file.get() 在 C++ 循环后返回随机数

c++ - Qt Mac - 应用程序在关闭后无法恢复

python - 如何使用 Keras TimeseriesGenerator

python - ValueError : Error when checking target: expected dense_10 to have shape (1, )但得到了形状为(19316,)的数组

macros - 在另一个宏的字符串参数中使用 Freemarker 宏调用

c++ - 动态多态和动态内存分配