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

macOS: disable fixup chains when linking extension modules #4301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,13 @@ using ``pip`` or ``conda``. If it hasn't, you can also manually specify
``-I <path-to-pybind11>/include`` together with the Python includes path
``python3-config --includes``.

On macOS: the build command is almost the same but it also requires passing
the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
building the module:
On macOS: the build command is almost the same but it also requires passing the
``-undefined dynamic_lookup -Wl,no_fixup_chains`` flag to ignore missing symbols
when building the module:

.. code-block:: bash

$ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
$ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup -Wl,no_fixup_chains $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)

In general, it is advisable to include several additional build parameters
that can considerably reduce the size of the created binary. Refer to section
Expand Down
6 changes: 4 additions & 2 deletions tools/pybind11Common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,17 @@ if(CMAKE_VERSION VERSION_LESS 3.13)
set_property(
TARGET pybind11::python_link_helper
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES "$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
PROPERTY INTERFACE_LINK_LIBRARIES
"$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup -no_fixup_chains>")
else()
# link_options was added in 3.13+
# This is safer, because you are ensured the deduplication pass in CMake will not consider
# these separate and remove one but not the other.
set_property(
TARGET pybind11::python_link_helper
APPEND
PROPERTY INTERFACE_LINK_OPTIONS "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
PROPERTY INTERFACE_LINK_OPTIONS
"$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup,-no_fixup_chains>")
endif()

# ------------------------ Windows extras -------------------------
Expand Down