Ask Your Question

Specify gcc -pg option for catkin?

asked 2017-05-19 23:55:58 -0600

deedub gravatar image

Hi all,

I am working on a project to do some performance profiling on amcl. To do this, I want to use gprof. To use gprof, I need to compile amcl with the -pg option for gcc. How can I do this in the catkin environment? Is this the right approach?

Bonus question: I don't really want to profile all of the navigation package, only amcl. How can I break amcl out of the navigation package so that I am only profiling amcl?

thanks in advance!


edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2017-05-24 12:15:25 -0600

paulbovbel gravatar image

The preferred approach is to modify the package's CMakeLists.txt to change the compile options:

set_directory_properties(PROPERTIES COMPILE_OPTIONS "-pg")

This will modify the compile options for the whole package, but won't bleed into other packages accidentally due to cmake include.

There's also ways to modify compile options per target (so just for one library or executable), see

edit flag offensive delete link more


Thanks very much for your answer. Just to clarify, this is preferable specifically because it won't bleed into other packages accidentally?

deedub gravatar image deedub  ( 2017-05-24 15:40:05 -0600 )edit

Correct. catkin_make will actually magically combine all your package cmakes into one. catkin_make_isolated or the very awesome catkin-tools will properly isolate packages, making set(CMAKE_CXX_FLAGS ...) slightly more tenable.

paulbovbel gravatar image paulbovbel  ( 2017-05-25 13:16:26 -0600 )edit

answered 2017-05-21 19:42:56 -0600

allenh1 gravatar image

You can simply add it to the CMakeLists.txtfile.

edit flag offensive delete link more


I used this snippet on the amcl/CMakeLists.txt file and it worked perfectly. Thanks!

deedub gravatar image deedub  ( 2017-05-24 15:31:34 -0600 )edit

answered 2020-10-08 03:59:33 -0600

AlexisTM gravatar image

updated 2020-10-08 04:00:13 -0600

Another way to run it over the whole workspace without changing the CMakeLists.txt is to use command-line arguments:

catkin build  --cmake-args -DCMAKE_C_FLAGS="-pg" -DCMAKE_CXX_FLAGS="-pg" --
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-05-19 23:55:58 -0600

Seen: 778 times

Last updated: Oct 08