-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Can't include Python.h from C++ code on macOS Sonoma / Clang 15 #110845
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
Comments
What is your clang version? |
Also, please add a minimal example on how to reproduce the issue. FWIW, I tried to reproduce using the following trivial code as a c++ file (.cc suffix): #include <cctype>
#include "Python.h" This worked fine when building with "cc -c repro.cc" using the clang included with the current Xcode 15.1 beta. Version Details
Xcode:
Clang:
|
This triggers it for me: cc `python3.11-config --includes` -fmodules -fcxx-modules test.cpp |
Can you provide the minimum test.cpp file reproducing the issue? |
The two-line file in my previous comment is enough to reproduce the issue (with 3.9 or later) The error goes away if I add Actually avoiding the error requires non-trivial reorganisation of our header files to ensure that all includes of system headers are done outside of |
It looks like these changes for 3.13 already have the correct reorganization, they'd just need to be backported: #108769 |
@vstinner : Are the changes in #108769 something that can be back ported to 3.11 and 3.12? I'm worried that moving includes around can affect 3th-party extensions. Alternatively we can document that Python 3.12 and earlier don't support building with C++ modules enabled, and add a test based on my earlier message to 3.13 to ensure that building with modules continues working there. |
I reproduced a similar error using a manually created C++20 module. Work in the Create
Create
Pre-compile
Modify extern "C" {
import mymodule;
} Build the C++ extension with:
Building the C++ extension fails with:
What I understood:
In short:
|
The problem also exists for the internal C API: see #115105. |
Since only Python 3.12 is impacted (Python 3.11 no longer gets bugfixes) and the lack of activity for one year, I suggest closing this old issue as "WONT FIX". |
This issue has been fixed in Python 3.13. |
Bug report
Bug description:
Including Python.h on <3.13 from a .cpp file results in the following:
You can work around this on a per project basis with
-Wno-module-import-in-extern-c
, but that's still pretty annoying.This is due to an include of a system header from inside an
extern "C"
block, which LLVM doesn't seem to like anymore with default flags on macOS.I believe the changes related to #108769 will fix this. Can we get them backported?
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
macOS
The text was updated successfully, but these errors were encountered: