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

Fix -pthread handling in Debian buster #1021

Merged
merged 8 commits into from
Oct 7, 2019

Conversation

sloretz
Copy link
Contributor

@sloretz sloretz commented Aug 3, 2019

On Debian buster FindBoost.cmake blindly adds ${CMAKE_THREAD_LIBS_INIT} to ${Boost_LIBRARIES} when the component thread is found. FindThreads.cmake sets that variable to -pthread. This breaks a bunch of stuff because -pthread is a linker flag, not a library.

There were earlier fixes for -lpthread, and this PR expands upon them. First this modifies the fix from #998 to not add -l to any linker flag. Second it adds to the fix in #975 to make sure -pthread is passed to downstream users. There's no standard cmake variable for linker flags, so this PR opts to create an interface target with just the flag, and add that to ${PROJECT_NAME}_LIBRARIES instead.

Both this PR and ros-visualization/python_qt_binding#68 are required to strip or qt_gui_cpp will fail at link time.

FindBoost.cmake blindly adds `${CMAKE_THREAD_LIBS_INIT}` to
`${Boost_LIBRARIES}` when the component `thread` is found.
On Debian buster the `FindThreads.cmake` sets that to `-pthread`.
This breaks a bunch of stuff becakse `-pthread` is a linker flag, not a
library.

There were earlier fixes for `-lpthread`.
This PR expands upon them.
First this PR modifies the fix from ros#998 to not add `-l` to any linker flag.
Second it adds to the fix in ros#975 to make sure `-pthread` is passed to
downstream users.
There's no standard cmake variable for linker flags, so this PR opts to
create an interface target with just the flag, and add that to
`${PROJECT_NAME}_LIBRARIES` instead.

Both this PR and ros-visualization/python_qt_binding#68 are required to strip or `qt_gui_cpp` will fail at link time.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

Another alternative would be to just leave the linker options out of the pkgConfig file and let the user deal with it...

if(NOT @PROJECT_NAME@_NUM_DUMMY_TARGETS)
set(@PROJECT_NAME@_NUM_DUMMY_TARGETS 0)
endif()
MATH(EXPR VAR "${@PROJECT_NAME@_NUM_DUMMY_TARGETS}+1")
Copy link
Member

Choose a reason for hiding this comment

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

This line is a no op since the result is assigned to the variable VAR which isn't used anywhere. I assume the intention was to increment @PROJECT_NAME@_NUM_DUMMY_TARGETS?

Nitpick: the CMake function name should be lower case to match the style guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lowercase and actually used output in 64295ca

set(@PROJECT_NAME@_NUM_DUMMY_TARGETS 0)
endif()
MATH(EXPR VAR "${@PROJECT_NAME@_NUM_DUMMY_TARGETS}+1")
add_library("catkin::@PROJECT_NAME@::dummy${@PROJECT_NAME@_NUM_DUMMY_TARGETS}" INTERFACE IMPORTED)
Copy link
Member

Choose a reason for hiding this comment

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

Since the target name is visible in downstream packages I would rather prefer a different name, maybe "wrapped-linker-optionN"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just wrapped-linker-optionN or catkin::my-project::wrapped-linker-optionN?

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind. While the first is unlikely to collide the second one should really not 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed target name in 8d6694a

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz
Copy link
Contributor Author

sloretz commented Aug 13, 2019

With this Dockerfile

ARG base_image

FROM $base_image

RUN apt update && apt install -y python-pip git cmake

RUN pip install argparse catkin-pkg empy mock nose

RUN git clone -b pthread-linker-fix https://github.com/sloretz/catkin.git \
 && mkdir catkin_build \
 && cd catkin_build \
 && cmake ../catkin \
 && make \
 && CTEST_OUTPUT_ON_FAILURE=1 make test

I checked this PR using

docker build --no-cache --build-arg base_image=ubuntu:xenial --force-rm . \
&& docker build --no-cache --build-arg base_image=ubuntu:bionic --force-rm . \
&& docker build --no-cache --build-arg base_image=debian:stretch --force-rm . \
&& docker build --no-cache --build-arg base_image=debian:buster --force-rm .

All builds succeeded, so the tests pass on those 4 platforms.

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz
Copy link
Contributor Author

sloretz commented Oct 7, 2019

@dirk-thomas I think this is ready for another review. In addition to the 4 Docker images in #1021 (comment) building successfully, I'm able to build all of Melodic upstream development up to desktop_full with Python 3 (with a few patches to other packages, skipping test_tf2) on Debian Buster using this PR merged with kinetic-devel.

@dirk-thomas dirk-thomas merged commit c3c645b into ros:kinetic-devel Oct 7, 2019
@sloretz sloretz deleted the pthread-linker-fix branch October 7, 2019 22:57
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.

2 participants