Can be used in Visual Studio Code
Features:
- Building C++ files using Bazel in Visual Studio Code
- Testing your code using Google Test
- Debugging with CodeLLDB Extension to provide pretty printing for STL containers such as
std::map
andstd::vector
.
You can use this template for most of your C++ projects without the need for changing the BUILD files.
git clone https://github.com/ourarash/cpp-template.git
You can run this using blaze
:
bazel run src/main:main
You can run unit tests using blaze
:
bazel test tests:tests
This repo uses Bazel
for building C++ files.
You can install Bazel using this link.
There are two configurations available: (lldb) launch
and CodeLLDB
. You can use (lldb) launch
without any modifications, but Currently only CodeLLDB
provides correct pretty printing for STL containers such as map and vector.
In order for CodeLLDB to work with Bazel on Visual studio code and provide pretty printing, you need the following:
- Install CodeLLDB Extension
- Run this command to create Bazel symlinks:
bazel build src/main:main
- Run one of the following commands depending on your system (copied from launch.json) to build with bazel for debug.
"Linux": "bazel build --cxxopt='-std=c++11' src/main:main -c dbg",
"windows": "bazel build --cxxopt='-std=c++11' src/main:main --experimental_enable_runfiles -c dbg"
"mac":"command": "bazel build --cxxopt='-std=c++11' src/main:main -c dbg --spawn_strategy=standalone"
- Run this in the root of your workspace to find the target of
bazel-cpp-template
symlink that Bazel creates based. These symlinks are documented here:
readlink -n bazel-cpp-template
- Put the output of that command in launch.json's sourcemap section:
"sourceMap": {
"[output of readlink -n bazel-cpp-template]": "${workspaceFolder}/"
}
Example:
"sourceMap": {
"/private/var/tmp/_bazel_ari/asdfasdfasdfasdfasdfgadfgasdg/execroot/__main__": "${workspaceFolder}/"
}
- Start debugging!
Here is a video that explains more about how to use Visual Studio Code for debugging C++ programs:
Here is a video that explains more about how to use Google Test with Bazel in Visual Studio Code:
Check this page.
The initial version of this repo was inspired by this post.