Everything happens under your drake/ folder.
To build the whole folder:
bazel build //...
//means the root path of your drake folder, it equals
...means build everything. Build everything can take a long time. We can speed up the building by narrowing down to a subfolder. For example, to build all targets under a subfolder:
bazel build //tools/...
Or to build a specific target:
bazel build //tools:drake_visualizer
bazelthat the path of the target is drake/tools/. What's followed after
:is the target
bazelwill find the
BUILD.bazelfile under drake/tools/ and build the target based on the rules defined in the
To run a specific executable:
bazel run //examples/double_pendulum:double_pendulum_demo
bazel runwill detect the relevant file modification. If the files are changed, this command will build first and then run immediately after the build.
:is followed by the executable binary, in this case,
Another way to run the binary is to type the binary name directly in the terminal. It does not check the file change nor recompile. All the
bazelbinaries are put in the drake/bazel-bin/ folder after being built. The detailed location of an executable is defined by
How to find where is the executable? Well, check the
BUILD.bazelfile and find the
drake_cc_binaryitem. The executable sits in the
using gdb to debug when you find errors like segmentation fault comes handy. We could compile the executable with gdb by:
bazel build --compilation_mode=dbg //examples/multibody/inclined_plane_with_body
Then you could run the executable with gdb inspecting the variables and function calls. When there is a error and program crashes, we could trace back to where it went wrong.
(gdb) run # execute the program and record the runtime stack data
(gdb) bt # back trace to where the program crashes and figure the problem
This command applies when you wrote your own function and test cases. Then you could test your cases by:
bazel test //common:polynomial_test
Commands in this page are enough to handle most cases.