What this thread does
Do first: set extra_compile_args on the affected Extension and inspect whether its required option is last in the emitted compiler invocation.
Short answer
As of November 2026, setuptools 84.2.1 documents per-extension compile and link arguments separately. For GCC, extra_compile_args=["-O0"] overrides an earlier optimization level because the last -O option wins (GCC).
Choose / don't choose
- Per-extension arguments: choose when only one extension needs an override; don't change every extension's flags to accommodate one module. PEP 831, created March 14, 2026, explicitly describes a per-extension frame-pointer opt-out.
- Environment flags: choose when the entire build needs the same compiler policy (setuptools).
Not for: missing setuptools or pkg_resources imports; see distutils-pkg-resources-pip-build-errors-and-torch-wheels.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
extra_compile_args | List of compiler options, e.g. ["-O0"] for GCC debugging; appended after include flags | setuptools 84.2.1 / GCC | extension, GCC |
extra_link_args | List of linker options for this extension; placed after runtime-library directory options | setuptools 84.2.1 | extension |
CFLAGS | The source selects os.environ.get('CFLAGS', cflags) | Linked Unix compiler source | source |
LDFLAGS | Environment linker options; keep per-extension compile arguments separate | Current setuptools extension docs | source |
CC / LDSHARED | Set only to select the required compiler/shared-link command; environment values override same-name sysconfig commands | setuptools 84.2.1 | extension |
Order of operations
1. Identify the compiler and the actual setuptools version used by the build frontend. Read the full compiler invocation, including wrapper-injected flags, rather than inferring it from an environment assignment. 2. In the tagged Unix source, the C flag selection is cflags = os.environ.get('CFLAGS', cflags). The source then applies cflags = _add_flags(cflags, 'CPP'). Other backends and older releases may compose differently. 3. Check the conflicting option's own compiler semantics. For a justified frame-pointer opt-out, PEP 831 names -fomit-frame-pointer in extra_compile_args (PEP). 4. Inspect the separate link invocation. Use environment linker options and extension-specific trailing options with extra_link_args; compilation success does not establish correct library search or linking (extension).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| Multiple optimization options | The last -O option is effective | Find the last optimization option and put the intended value in that extension's trailing arguments | GCC, source |
Missing
- No universal override exists for an unsupported or ABI-incompatible compiler option; determine its exact meaning and origin before removing it.
- The first setuptools release changing historical CFLAGS composition is not established here; the ordering above is scoped to the linked tag.
Checked
2026-11-12; setuptools 84.2.1 release, extension reference and tagged Unix compiler source; GCC optimization reference and dated PEP 831 read. No extension build executed.
Started from a post by @setuptools, packaged by the editor. Original post