Skip to content

Commit 2ecfcfd

Browse files
committed
Change macOS handling of undefined symbols
Newer version of XCode deprecate the ``-undefined dynamic_lookup`` flag that pybind11 has used to avoid linking to a specific Python shared library. Every use of it now lead to the following noisy warning message. ``` ld: warning: -undefined dynamic_lookup may not work with chained fixups ``` More details on this are available here: https://mjtsai.com/blog/2021/06/30/faster-app-launching-in-ios-15-and-monterey/ While this seems somewhat specific to Swift, it is problematic if a core linker feature that pybind11 depends on is declared unreliable. I have been able to replace these flags with ``` -undefined suppress -flat_namespace ``` I am not sure if this suits everyone. The purpose of the PR is to raise the issue and starts a discussion on what to do.
1 parent 252ed8f commit 2ecfcfd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/compiling.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,12 @@ using ``pip`` or ``conda``. If it hasn't, you can also manually specify
583583
``python3-config --includes``.
584584

585585
On macOS: the build command is almost the same but it also requires passing
586-
the ``-undefined dynamic_lookup`` flag so as to ignore missing symbols when
586+
the ``-undefined suppress -flat_namespace`` flag so as to ignore missing symbols when
587587
building the module:
588588

589589
.. code-block:: bash
590590
591-
$ c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
591+
$ c++ -O3 -Wall -shared -std=c++11 -undefined suppress -flat_namespace $(python3 -m pybind11 --includes) example.cpp -o example$(python3-config --extension-suffix)
592592
593593
In general, it is advisable to include several additional build parameters
594594
that can considerably reduce the size of the created binary. Refer to section

tools/pybind11Common.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ if(CMAKE_VERSION VERSION_LESS 3.13)
7575
set_property(
7676
TARGET pybind11::python_link_helper
7777
APPEND
78-
PROPERTY INTERFACE_LINK_LIBRARIES "$<$<PLATFORM_ID:Darwin>:-undefined dynamic_lookup>")
78+
PROPERTY INTERFACE_LINK_LIBRARIES "$<$<PLATFORM_ID:Darwin>:-undefined suppress -flat_namespace>")
7979
else()
8080
# link_options was added in 3.13+
8181
# This is safer, because you are ensured the deduplication pass in CMake will not consider
8282
# these separate and remove one but not the other.
8383
set_property(
8484
TARGET pybind11::python_link_helper
8585
APPEND
86-
PROPERTY INTERFACE_LINK_OPTIONS "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,dynamic_lookup>")
86+
PROPERTY INTERFACE_LINK_OPTIONS "$<$<PLATFORM_ID:Darwin>:LINKER:-undefined,suppress,-flat_namespace>")
8787
endif()
8888

8989
# ------------------------ Windows extras -------------------------

0 commit comments

Comments
 (0)