我想从 cc 文件中读取附近的文件。我插入了 data
属性,但它似乎在附近找不到 data.txt。
结构:
├── root
│ ├── BUILD
│ ├── data.txt
│ └── main.cc
└── WORKSPACE
在构建文件中:
cc_binary(
name = "test",
srcs = ["main.cc"],
data = ["data.txt"]
)
在main.cc文件中:
#include <iostream>
#include<fstream>
using namespace std;
int main(){
ifstream myReadFile;
myReadFile.open("data.txt");
if (!myReadFile.good()){
cout << "FILE not good!" << endl;
return 1;
}
cout << "FILE is good!" << endl;
return 0;
}
最佳答案
假设您从顶级目录(包含 WORKSPACE
的目录)构建,使用 bazel build root:test
,并使用 运行代码bazel-bin/root/test
,文件应指定为root/data.txt
。
关于c++ - Bazel:本地访问附近的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58092561/