【问题标题】:Cannot successfully include external header file through cc_library rule for bazel无法通过 bazel 的 cc_library 规则成功包含外部头文件
【发布时间】:2017-07-06 20:54:21
【问题描述】:

我无法通过 bazel 中的构建命令包含一些头文件。我遵循了他们包含在 bazel 文档中的example

这是我的构建文件

cc_library(
    name = "hello-greet",
    srcs = ["hello-greet.cc"],
    hdrs = ["hello-greet.h"],
    copts = ["-Imain/include"]
)

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
        ":hello-greet",
    ],
)

下面是我的目录结构。

  • 工作空间
  • 主要
    • 包括
      • hello-greet.h
    • hello-greet.cc
    • hello-world.cc
    • 构建

我不知道这是否会有所帮助,但这里有一些源文件和头文件的代码。

hello-greet.cc

#include "hello-greet.h"
#include <string>

std::string get_greet(const std::string& who) {
  return "Hello " + who;
}

你好世界.cc

#include "hello-greet.h"
#include <ctime>
#include <iostream>
#include <string>

void print_localtime() {
  std::time_t result = std::time(nullptr);
  std::cout << std::asctime(std::localtime(&result));
}

int main(int argc, char** argv) {
  std::string who = "world";
  if (argc > 1) {
    who = argv[1];
  }
  print_localtime();
  return 0;
}

当我运行 bazel build 命令时,它会报错

INFO: Found 1 target...
ERROR: missing input file '//main:hello-greet.h'.

【问题讨论】:

    标签: c++ bazel


    【解决方案1】:

    你应该可以通过将includes = "." 添加到cc_library 来做你想做的事(不需要copts

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-04
      • 2019-12-19
      • 2017-12-01
      • 1970-01-01
      相关资源
      最近更新 更多