tf2 error when switching from catkin_make to catkin_make_isolated

asked 2021-07-14 09:35:18 -0500

aa-tom gravatar image

updated 2021-07-14 14:24:59 -0500

I'm trying to migrate from using catkin_make to catkin build using this guide, which recommends using catkin_make_isolated as an intermediate step to determine whether the packages are suitable for building in isolation.

I'm getting an issue building one package using catkin_make_isolated, which seems to stem from an issue within the tf2 dependency. I'm a little confused as to why switching causes the issue to appear as the tf2 code hasn't been changed. I'm wondering if there's a flag not being passed to the compiler as a result of the switch, but I'm not entirely sure what I should be looking for. Any help would be much appreciated!

Below is an excerpt of the output from the build showing the errors:

/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:329:17: error: The address of local variable 'd' is accessed at non-zero index. [objectIndex]
    dst[0] = src[3];
                ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:327:43: note: Address of variable taken here.
    unsigned char *src = (unsigned char *)&d;
                                          ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:329:17: note: The address of local variable 'd' is accessed at non-zero index.
    dst[0] = src[3];
                ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:330:8: error: The address of local variable 'a' is accessed at non-zero index. [objectIndex]
    dst[1] = src[2];
       ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:326:43: note: Address of variable taken here.
    unsigned char *dst = (unsigned char *)&a;
                                          ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:330:8: note: The address of local variable 'a' is accessed at non-zero index.
    dst[1] = src[2];
       ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:330:17: error: The address of local variable 'd' is accessed at non-zero index. [objectIndex]
    dst[1] = src[2];
                ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:327:43: note: Address of variable taken here.
    unsigned char *src = (unsigned char *)&d;
                                          ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:330:17: note: The address of local variable 'd' is accessed at non-zero index.
    dst[1] = src[2];
                ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:331:8: error: The address of local variable 'a' is accessed at non-zero index. [objectIndex]
    dst[2] = src[1];
       ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:326:43: note: Address of variable taken here.
    unsigned char *dst = (unsigned char *)&a;
                                          ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:331:8: note: The address of local variable 'a' is accessed at non-zero index.
    dst[2] = src[1];
       ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:331:17: error: The address of local variable 'd' is accessed at non-zero index. [objectIndex]
    dst[2] = src[1];
                ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:327:43: note: Address of variable taken here.
    unsigned char *src = (unsigned char *)&d;
                                          ^
/opt/ros/noetic/include/tf2/LinearMath/Scalar.h:331:17: note: The address of local variable 'd' is accessed at non-zero index.
    dst[2 ...
(more)
edit retag flag offensive close merge delete

Comments

I've found that commenting out the following lines in my CMakeLists.txt file prevents the error:

if(NOT CATKIN_ENABLE_TESTING)
    set(CMAKE_CXX_CPPCHECK cppcheck;--std=c++17;--error-exitcode=1)
endif()
aa-tom gravatar image aa-tom  ( 2021-07-14 09:40:29 -0500 )edit

Tried pulling the code for tf2 down and running what I presume is the same command catkin is running under the hood, but was unable to replicate the issue

...
27/34 files checked 91% done
Checking tf2_ros/src/static_transform_broadcaster_program.cpp ...
28/34 files checked 93% done
Checking tf2_ros/src/transform_broadcaster.cpp ...
29/34 files checked 94% done
Checking tf2_ros/src/transform_listener.cpp ...
30/34 files checked 95% done
Checking tf2_ros/test/listener_unittest.cpp ...
31/34 files checked 96% done
Checking tf2_ros/test/message_filter_test.cpp ...
32/34 files checked 97% done
Checking tf2_ros/test/time_reset_test.cpp ...
33/34 files checked 98% done
Checking tf2_sensor_msgs/test/test_tf2_sensor_msgs.cpp ...
34/34 files checked 100% done
aa-tom gravatar image aa-tom  ( 2021-07-14 10:01:50 -0500 )edit

From what you describe, I don't believe this would be an issue with catkin_tools, nor with catkin_make_isolated.

Tbh, the "migration" tutorial is a bit too conservative.

If packages don't build with catkin_tools, it's not really seriously more complex to diagnose that with catkin_tools than it is with catkin_make_isolated.

Often seen problems mostly include build order issues due to people not having stated their build_depends properly in the manifest.

A lot of these can be detected by catkin_lint.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 10:06:09 -0500 )edit

Thanks for pointing me in the direction of catkin lint. It seems super handy. I ran it over the culprit package and fixed the errors (missing build_depends as you said) but still getting the tf2 issue when building

aa-tom gravatar image aa-tom  ( 2021-07-14 13:37:35 -0500 )edit

If you post your CMakeLists.txt we might be able to spot something.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 13:40:08 -0500 )edit

Sure thing. I've added it to the end of my original post.

aa-tom gravatar image aa-tom  ( 2021-07-14 13:53:03 -0500 )edit

I'm confused now btw: the error message you mention:

error: The address of local variable 'd' is accessed at non-zero index. [objectIndex]

is a cppcheck error.

It's not a compilation error.

Tried pulling the code for tf2 down and running what I presume is the same command catkin is running under the hood,

what do you mean by this exactly?

This also confuses me:

if(NOT CATKIN_ENABLE_TESTING)

so you want to run cppcheck if testing is disabled?

gvdhoorn gravatar image gvdhoorn  ( 2021-07-14 13:56:56 -0500 )edit

The file wasn't written by me, so not entirely sure why it's its set to run when testing is disabled. I'll have to chat to the author about that! Agree that cppcheck is at the heart of the issue, but I'm a little confused as to why the error only shows up when using catkin build. catkin_make compiles (and presumably checks) the same code just fine. I tried cloning the geometry2 repository and running cpp over the code manually using

cppcheck . --std=c++17 --error-exitcode=1

but can't reproduce the issue...

aa-tom gravatar image aa-tom  ( 2021-07-14 14:04:50 -0500 )edit