1

Im trying to access runfiles within c++. Im using Bazel 5.2.0. I tried to access like this:

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 is right, just to lazy to change) The program is finding a path but the path starts from the bazelisk directory and doesn't point to the binary dir.

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

Im getting this as an result. Maybe there is a new way to access runfiles but Im not finding it.

Nov0cx
  • 11
  • 2
  • 1
    Would you mind posting your BUILD files as well it's kind of challenging to help you with your query without it? – silvergasp Aug 01 '22 at 16:32

1 Answers1

0

The answer is you have to include the workspace name in the path, if it isn't set you have to use __main__.
Closed.

Nov0cx
  • 11
  • 2