-
Notifications
You must be signed in to change notification settings - Fork 39
Use "LINKER:-undefined,dynamic_lookup" to avoid wrong deduplication #657
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @traversaro , LGTM, I'll let @scotts take a look and merge since this relates to the MacOS pybind extension build
I see that there is a CI failure on 4.4.2, not sure if it is related:
Even if also here I see a mixture of (in general) incompatible channels |
The 4.4.2 CI failures are pre-existing, I see them on #635 as well which is unrelated, so we can ignore it for this PR |
Thanks @traversaro! To solve the mystery of why you need to manually add |
Interesting. However I am still surprised as apparently you link
pybind11::module was linking the pybind11::python_link_helper . But looking in the pybind11 CMake code, it seems that pybind11::module does link pybind11::python_link_helper see https://github.com/pybind/pybind11/blob/bc4a66dff0464d0c87291b00a3688999fea5bedc/tools/pybind11NewTools.cmake#L251-L254C49 (while if Python3::Module is defined, it links to it, but in CMake there is a similar logic: https://github.com/Kitware/CMake/blob/9debf90d87c2ad94046b092773deb4314a3f0aa0/Modules/FindPython/Support.cmake#L4302-L4312). So at a first glance is not really a matter of using pybind11's CMake helper, but the LINKER:-undefined,dynamic_lookup should already come by linking to pybind11::module .
|
The
-undefined dynamic_lookup
option is passed to the Python extension to avoid segfault when loading the Python extension on macOS on a Python interpreter that statically links tolibpython
(such as the conda one), see conda-forge/python-feedstock#595 .However, on conda-forge builds this option results in linker-related errors:
I am not sure why this does not happen in the upstream CI, probably the version of the compiler and the linker are slightly different.
However, in a nutshell the error is there as the option deduplication (see https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication) is done in the wrong way.
As the minimum CMake version is 3.18, we can avoid this wrong deduplication by using the
LINKER:
prefix, as documented in https://cmake.org/cmake/help/latest/command/target_link_options.html#handling-compiler-driver-differences and done indeed by pybind11 in https://github.com/pybind/pybind11/blob/v2.13.6/tools/pybind11Common.cmake#L122 .Note that from what I understand, this should not be necessary to do here as this is already done by pybind11 in https://github.com/pybind/pybind11/blob/v2.13.6/tools/pybind11Common.cmake#L122, but I do not fully understand the whole build-related subtleties, so the proposed change should fix the problem without changing anything else.