Ask Your Question
0

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

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

OwnageManFromLOL 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 imagegvdhoorn ( 2018-06-21 02:32:06 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

gvdhoorn gravatar image

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

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 imageOwnageManFromLOL ( 2018-06-21 18:56:36 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 416 times

Last updated: Jun 21 '18