Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent compiler warnings via -isystem includes #102

Open
wants to merge 1 commit into
base: melodic-devel
Choose a base branch
from

Conversation

rhaschke
Copy link
Contributor

rviz' CI is frequently failing because of compiler warnings in include files external to the actual source tree. While Debian Buster uses an older gcc version and thus isn't affected, warnings on the ROS buildfarm for Ubuntu Focal turn into failures in github's CI.

The obvious solution is to mark external includes using -isystem instead of -I. However, this causes issues if /usr/include is included like this as well - either directly or indirectly via relative paths or symlinks. Hence, the second change of this PR filters out these paths.

Copy link
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The obvious solution is to mark external includes using -isystem instead of -I. However, this causes issues if /usr/include is included like this as well - either directly or indirectly via relative paths or symlinks.

What happens if /usr/include is included as an -isystem include?

@@ -92,6 +99,7 @@ function(build_sip_binding PROJECT_NAME SIP_FILE)
add_custom_command(
OUTPUT ${SIP_BUILD_DIR}/Makefile
COMMAND ${PYTHON_EXECUTABLE} ${sip_SIP_CONFIGURE} ${SIP_BUILD_DIR} ${SIP_FILE} ${sip_LIBRARY_DIR} \"${INCLUDE_DIRS}\" \"${LIBRARIES}\" \"${LIBRARY_DIRS}\" \"${LDFLAGS_OTHER}\" \"${EXTRA_DEFINES}\"
COMMAND sed -i 's/ -I/ -isystem/g' ${SIP_BUILD_DIR}/Makefile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are windows users, and it seems like requiring sed would be a problem there. Can we do this in sip_configure.py after generating the makefile?

Copy link
Contributor Author

@rhaschke rhaschke Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that will be possible. But, I will not have cycles to do that in any near future. I am using the present patch since several months already and just barely managed to file the PR now.

foreach(dir ${${PROJECT_NAME}_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
get_filename_component(dir_real "${dir}" REALPATH BASE_DIR ${sip_SOURCE_DIR})
# filter out /usr/include, which must not be included via -isystem
if (NOT "${dir_real}" STREQUAL "/usr/include")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why filtering /usr/include is necessary, but I'm willing to try it in Noetic and see if it causes issues.

@rhaschke
Copy link
Contributor Author

What happens if /usr/include is included as an -isystem include?

Sorry for not providing this info in first place. See e.g. here on stackoverflow.

@wjwwood
Copy link
Member

wjwwood commented Apr 15, 2021

I'll just mention that we've had issues in the past with -isystem being used in combination with -I in the past. Basically if it was -IA -IB -IC and foo.hpp existed in all three, you'd take it from -IC, but if you changed it to -IA -isystemB -IC then it might change which version of foo.hpp was selected. I'm not sure that's exactly right (might have the scenario a bit wrong), and it only came up in overlaying scenarios, but we did have problems with it at some point and actually removed the use of -isystem in a lot of places.

This was years and years ago, so maybe it's worth doing now, but I just wanted to bring it up.

After looking, I guess @sloretz you're already aware of this, based on this: ros2/pybind11_vendor#9

And it leads to somewhat fragile proposed workarounds like this: ros2/rosbag2#623

Basically -isystem has been really annoying in the past.

It's more annoying to do so, but I think disabling warnings around include statements within rviz's code base is safer, but that's definitely a personal preference kind of choice.

@rhaschke
Copy link
Contributor Author

@wjwwood, is the problem explained by this note in the gcc docs?

If a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option is ignored. The directory is still searched but as a system directory at its normal position in the system include chain.

This suggests that if you specify an include path both as -I and -isystem, it will be ignored for the high-priority -I search and only considered later when processing all -isystem includes. For me, that reads like all external include paths should be marked consequently with -isystem.

@wjwwood
Copy link
Member

wjwwood commented Apr 15, 2021

It could be that using -isystem for "everything external" could work, but that's not the case right now. Using it sometimes is the issue I think though.

@sloretz
Copy link
Contributor

sloretz commented Apr 15, 2021

It could be that using -isystem for "everything external" could work, but that's not the case right now. Using it sometimes is the issue I think though.

IIUC in ROS 2 everything is -isystem because that's the default for imported CMake targets.

Since this PR is ROS 1, IIRC catkin uses CMake variables and does some workspace aware include directory ordering. The order in the gcc docs means that probably breaks when -I or -isystem are mixed.

Sorry for not providing this info in first place. See e.g. here on stackoverflow.

Ah got it. It seems to be this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129 . CMake itself works around that as of https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2716 . One comments says appending /usr/include to CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES will work around the issue in the meantime.

@rhaschke
Copy link
Contributor Author

Note that the sip stuff doesn't use cmake. It directly creates a make file and this PR suggests replacing all -I with -isystem. Hence, there is no risk to mix them - everything is -isystem in the end (only for compiling the sip bindings). So, I think it would be safe to apply this PR. Of course, sed should be replaced by python...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants