-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: remove -stdlib=libc++ from setup helpers, not needed on modern Pythons #4639
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
e20d6df
to
e586135
Compare
Just tested it on an Apple Silicon macOS development server, but please be sure to double check it, I have no prior experience with pybind11. |
…#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>
hasflag is slow and probably not supported correctly when cross-compiling, so not sure I like adding more usages of it. Is there a better way to tell if the target compiler is clang? Also, do we really need it? I think this was only important when |
I cannot think of a better idea... Sometimes, even
If legacy compatibility is unimportant, this flag can be removed entirely. |
New idea: we can run |
Isn't Also I would like to suggest to rename |
Yeah, the check is better to be kept out of the loop.
It was my intention as well, somehow I forgot about it while editing the file... |
The only system I'm aware of that a user might run across with <10.9 as a target would be the original |
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.
@henryiii This PR looks good to go now, right? Any blockers?
Description
On macOS, by default, pybind11 currently unconditionally set the compiler flag
-stdlib=libc++
inPybind11Extension.__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: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.This PR resolves Issue #4637.
Suggested changelog entry: