How to colcon build RelWithDebInfo with no code optimizations ( -O0 )

asked 2021-11-15 11:46:42 -0600

Sunny127 gravatar image

Hi, I am trying to build a project with ros2 foxy windows, in RelWithDebInfo with no code optimizations ( -O0 ). The following line works:

colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo

However when I try to indicate I want all optimizations turned off, the project is built in release mode, with no .pdb files that are needed for debugging and putting breakpoints. The following line seems to ignore all flags and creates a release project, not RelWithDebInfo project:

colcon build --merge-install --event-handlers console_direct+ --cmake-args " -DCMAKE_BUILD_TYPE=RelWithDebInfo" --cmake-args " -DCMAKE_C_FLAGS_RELWITHDEBINFO=-g -O0" --cmake-args " -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-g -O0"

I saw at https://colcon.readthedocs.io/en/rele... that: --cmake-args [* [* …]] , Pass arbitrary arguments to CMake projects. Arguments matching other options must be prefixed by a space, e.g. --cmake-args " --help"

I tried many other variants but they all created Release projects, without any debug symbols ( Eventually I need RelWithDebInfo with no code optimizations ( -O0 ) :

colcon build --merge-install --cmake-args " -DCMAKE_BUILD_TYPE=Debug" --cmake-args " -DCMAKE_C_FLAGS_DEBUG=-g -O0" --cmake-args " -DCMAKE_CXX_FLAGS_DEBUG=-g -O0" --event-handlers console_direct+

colcon build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=Debug --cmake-args -DCMAKE_C_FLAGS_DEBUG="-g -O0" --cmake-args -DCMAKE_CXX_FLAGS_DEBUG="-g -O0" --event-handlers console_direct+

colcon build --merge-install --cmake-args "-DCMAKE_BUILD_TYPE=Debug" --cmake-args " -DCMAKE_C_FLAGS_DEBUG=-g -O0" --cmake-args " -DCMAKE_CXX_FLAGS_DEBUG=-g -O0" --event-handlers console_direct+

colcon build --merge-install --cmake-args " -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS_DEBUG="-g -O0" -DCMAKE_CXX_FLAGS_DEBUG="-g -O0" "

colcon build --merge-install --cmake-args " -DCMAKE_BUILD_TYPE=Debug" --cmake-args " -DCMAKE_C_FLAGS_DEBUG='-g -O0' " --cmake-args " -DCMAKE_CXX_FLAGS_DEBUG='-g -O0' "

Any ideas?

edit retag flag offensive close merge delete

Comments

Have you tried this?

colcon build --merge-install --event-handlers console_direct+ --cmake-args "-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS_RELWITHDEBINFO=-g -O0 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-g -O0"
Geoff gravatar image Geoff  ( 2021-11-15 16:54:06 -0600 )edit

Isn't it just -DCMAKE_BUILD_TYPE=Debug? What extra are you expecting to get from RelWithDebInfo + -O0?

KenYN gravatar image KenYN  ( 2021-11-16 01:37:25 -0600 )edit

@Geoff, Command:

colcon build --merge-install --event-handlers console_direct+ --cmake-args "-DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_FLAGS_RELWITHDEBINFO=-g -O0 -DCMAKE_CXX_FLAGS_RELWITHDEBINFO=-g -O0"

builds the project is built in release mode, with no .pdb files that are needed for debugging and putting breakpoints

Sunny127 gravatar image Sunny127  ( 2021-11-16 02:13:05 -0600 )edit

@KenYN I need RelWithDebInfo and not Debug, cause when running my project in Debug, it throws an exception at line

std::shared_ptr<rclcpp::Node> nh = rclcpp::Node::make_shared("my_node");

No exception is thrown when building in Release or RelWithDebInfo.

https://answers.ros.org/question/3910...

Sunny127 gravatar image Sunny127  ( 2021-11-16 02:17:05 -0600 )edit
1

You are better off figuring out why the exception happens than trying to ignore it by not building in Debug mode.

Geoff gravatar image Geoff  ( 2021-11-16 17:58:49 -0600 )edit

Note that make_shared() might not be thread-safe, so perhaps timing issues are coming into play. I agree with @Geoff on this.

KenYN gravatar image KenYN  ( 2021-11-17 00:28:59 -0600 )edit