ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

What does "catkin build <pkg_name> --cmake-args -DCMAKE_BUILD_TYPE=Release" actually do?

asked 2018-06-20 18:45:33 -0600

OwnageManFromLOL gravatar image

updated 2022-01-22 16:16:24 -0600

Evgeny gravatar image

I recently been exploring using these cmake-args to optimize my code. For the past few weeks I have just been running "catkin build <pkg_name>". Today when I ran "catkin build <pkg_name> --cmake-args -DCMAKE_BUILD_TYPE=Release" my code ran 10 times faster.

Should I always be running the second command instead with the build type explicitly mentioned as opposed to simply "catkin build <pkg_name>"? Is this a safe practice? I could not find much about this on the internet and I would greatly appreciate some advice.

edit retag flag offensive close merge delete

Comments

See #q172950 and #q71965 for what are almost duplicates btw.

gvdhoorn gravatar image gvdhoorn  ( 2018-06-21 02:32:06 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-06-21 01:40:09 -0600

gvdhoorn gravatar image

updated 2018-06-21 02:31:48 -0600

This is actually a CMake question, not really ROS-specific.

See CMAKE_BUILD_TYPE in the CMake documentation, and perhaps this random post about CMake build types for some more background.

The build type essentially just configures the compilers optimisation level.

Should I always be running the second command instead with the build type explicitly mentioned as opposed to simply "catkin build <pkg_name>"? Is this a safe practice?

this is not easily answerable I believe.

The Release build type will set the following flags: -O3 -NDEBUG (at least for GCC type compilers). That is just about the maximum amount of optimisation and a debug features (such as asserts) are completely disabled.

If you're compiling your code for release purposes, then setting that build type might make sense. Especially in cases where code can make use of processor optimisations (such as SSEx, AVX, etc), allowing such optimisation might be beneficial. You've noticed quite a speed-up yourself, so that could point to a situation where it would make sense to set Release as the build type (but be careful to do it correctly if you're contemplating doing it from within your CMakeLists.txt).

However, optimised builds will not contain any debug symbols, will not be easily debuggable and will have disabled a lot of things like assertions that would help you write correct code. gdb backtraces will be just about meaningless for optimised binaries (and not just because the symbols are missing).

So if you're still developing keeping the build type at its default makes more sense.

In cases where some optimisation is needed because otherwise your program doesn't work correctly (because it becomes too slow fi), the RelWithDebInfo build type might work.

edit flag offensive delete link more

Comments

Thank you very much for your response kind sir. I have been using std::cerr to debug my whole life. Now I have an alternative (y)

OwnageManFromLOL gravatar image OwnageManFromLOL  ( 2018-06-21 18:56:36 -0600 )edit

We got the same issue, were wondering if we could add build type for certain pkg into CMakeLists.txt rather than using command line (i.e. catkin_make -pkg <pkg_name> -DCMAKE_BUILD_TYPE=Release).

lukelu gravatar image lukelu  ( 2020-09-26 21:00:19 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-06-20 18:45:33 -0600

Seen: 3,193 times

Last updated: Jun 21 '18