Skip to content

Commit da91926

Browse files
biergaizihenryiii
andauthored
fix: remove -stdlib=libc++ from setup helpers, not needed on modern Pythons (#4639)
* Inject -stdlib=libc++ on macOS only when it's supported, close #4637. On macOS, by default, pybind11 currently unconditionally set the compiler flag "-stdlib=libc++" in Pybind11Extension.__init__(), regardless of which compiler is used. This flag is required for clang, but is invalid for GCC. If GCC is used, it causes compilation failures in all Python projects that use pybind11, with the error message: arm64-apple-darwin22-gcc: error: unrecognized command-line option -stdlib=libc++. This commit uses has_flag() to detect whether "-stdlib=libc++" on macOS, and injects this flag from build_ext.build_extensions(), rather than setting it unconditionally. Signed-off-by: Yifeng Li <tomli@tomli.me> * revert: just remove flags --------- Signed-off-by: Yifeng Li <tomli@tomli.me> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
1 parent 956390a commit da91926

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

pybind11/setup_helpers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
144144
self.cxx_std = cxx_std
145145

146146
cflags = []
147-
ldflags = []
148147
if WIN:
149148
cflags += ["/EHsc", "/bigobj"]
150149
else:
@@ -154,11 +153,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
154153
c_cpp_flags = shlex.split(env_cflags) + shlex.split(env_cppflags)
155154
if not any(opt.startswith("-g") for opt in c_cpp_flags):
156155
cflags += ["-g0"]
157-
if MACOS:
158-
cflags += ["-stdlib=libc++"]
159-
ldflags += ["-stdlib=libc++"]
160156
self._add_cflags(cflags)
161-
self._add_ldflags(ldflags)
162157

163158
@property
164159
def cxx_std(self) -> int:

0 commit comments

Comments
 (0)