gpt4 book ai didi

c - Bazel:寻址 header 的语法错误?

转载 作者:行者123 更新时间:2023-11-30 16:28:00 27 4
gpt4 key购买 nike

我遇到了一个问题,即使声明了头文件,也找不到它们。我的规则是按照此 answer 中所述生成的。但在执行过程中我收到错误,某些目标找不到它们依赖的头文件。

This is my folder structure:
component1/... /.../module1/(containing .c and .h files)
/... /.../module2/(containing .c and .h files)
/BUILD.bazel
/SrcList.bzl
/macro.bzl

构建文件如下所示。

cc_library(
name = "module1",
visibility = ["//visibility:public"],
deps = [],
srcs = ["//components/module1:target/src/module1.c"],
linkstatic = True,
hdrs = ["//components/module1:target/src/module1_1.h", "//components/module1:target/src/module1_2.h", "//components/module1:target/src/module1_3.h"],
)

cc_library(
name = "module2",
visibility = ["//visibility:public"],
deps = [:module1],
srcs = ["//components/module2:target/src/module2.c"],
linkstatic = True,
hdrs = ["//components/module2:target/src/module2_1.h", "//components/module2:target/src/module2_2.h", "//components/module2:target/src/module2_3.h"],
)

Src 文件使用#include "foo.h"结构。模块 2 依赖于模块 1。但是如果我启动构建规则 module2 找不到 module1 的 header 。我该如何解决这个问题?

最佳答案

这些目标不在工作区根目录下吗?

如果是这种情况,您将需要根据工作区根目录来建立头文件的根目录。请参阅https://github.com/bazelbuild/bazel/blob/master/examples/cpp/hello-lib.cc举个例子。请注意包括:

#include“examples/cpp/hello-lib.h”

关于c - Bazel:寻址 header 的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52552855/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com