How to add GProf flag in Bazel build
Lately I’ve decided to profile my C++ program (built with Bazel) with GProf. However, not until some googling did I realize that I need to…
How to add GProf flag in Bazel build
Lately I’ve decided to profile my C++ program (built with Bazel) with GProf. However, not until some googling did I realize that I need to add the “-pg” flag the following way to make the program generate the file gmon.out file:
bazel build — copt=”-pg” — cxxopt=”-pg” — linkopt=“-pg” {your target}
That’s because according to [2], the -pg flag needs to be passed at both complication and linking time, and Bazel does not pass options specified by — copt/ — cxxopt to linking. So one would need to pass -pg through the linker option — linkopt.
References:
[1] Bazel documentation: http://www.bazel.io/versions/master/docs/bazel-user-manual.html
[2]GProf FAQ: http://www.delorie.com/djgpp/v2faq/faq13_5.html
메타데이터
- post_id
- d3fdc1b2c138
- slug
- how-to-add-gprof-flag-in-bazel-build-d3fdc1b2c138
- url
- https://medium.com/@coderhead/how-to-add-gprof-flag-in-bazel-build-d3fdc1b2c138
- canonical_url
- https://medium.com/@coderhead/how-to-add-gprof-flag-in-bazel-build-d3fdc1b2c138
- author_url
- https://medium.com/@coderhead
- status
- ok
- fetched_at
- 2026-07-30 17:42:37