【问题标题】:How do you access runfiles with Bazel 5.2.0 in c++如何在 c++ 中使用 Bazel 5.2.0 访问运行文件
【发布时间】:2022-08-02 15:04:47
【问题描述】:

我试图在 C++ 中访问运行文件。我正在使用 Bazel 5.2.0。我试图这样访问:

std::string error;
std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0], &error));
if (!runfiles) {
    std::cerr << error << std::endl;
    return 1;
}

std::string path = runfiles->Rlocation(\"Test/Example.tx\");
std::cout << \"Example.tx: \" << path << std::endl;

std::ifstream in(path);

if (!in.is_open())
{
    std::cout << \"Example.tx not found\" << std::endl;
    return -1;
}

(Example.tx 是对的,只是懒得改) 该程序正在寻找一个路径,但该路径从 bazelisk 目录开始并且不指向二进制目录。

Example.tx: C:\\users\\nikla\\_bazel_nikla\\d47dtf2d\\execroot\\__main__\\bazel-out\\x64_windows-fastbuild\\bin\\Test\\Test.exe.runfiles/Test/Example.tx
Example.tx not found

结果我得到了这个。 也许有一种访问运行文件的新方法,但我没有找到它。

  • 您介意发布您的 BUILD 文件吗?没有它来帮助您进行查询是一种挑战吗?

标签: bazel bazel-rules bazel-cpp


【解决方案1】:

答案是您必须在路径中包含工作区名称,如果未设置,则必须使用主要的.
关闭。

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    相关资源
    最近更新 更多