我想调试用Bazel生成的可执行文件.使用Bazel生成的链接丢失了gdb调试器,并且无法向我显示C++源代码.如何解决?
项目根目录是/home/.../Cpp/
./Cpp/
??? bazel-bin -> /home/picaud/.cache/bazel/_bazel_picaud...
??? bazel-Cpp -> /home/picaud/.cache/bazel/_bazel_picaud...
??? bazel-genfiles -> /home/picaud/.cache/bazel/_bazel_picaud...
??? bazel-out -> /home/picaud/.cache/bazel/_bazel_picaud...
??? bin
? ??? BUILD
? ??? main.cpp
??? MyLib
? ??? BUILD
? ??? ....hpp
? ??? ...cpp
??? WORKSPACE
Run Code Online (Sandbox Code Playgroud) 我有一个(基本的)C++项目:
??? bin
? ??? BUILD
? ??? example.cpp
??? data
? ??? someData.txt
??? WORKSPACE
Run Code Online (Sandbox Code Playgroud)
可执行example.cpp使用data/目录中的一些数据文件:
#include <fstream>
#include <iostream>
int main()
{
std::ifstream in("data/someData.txt");
if (!in)
{
std::cerr << "Can not open file!";
return EXIT_FAILURE;
}
std::string message;
if (!(in >> message))
{
std::cerr << "Can not read file content!";
return EXIT_FAILURE;
}
std::cout << message << std::endl;
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
我的Bazel设置是最小的:
cc_binary(name = "example",srcs = ["example.cpp"])Hello_world! …