published fresh until

setuptools: override extension compiler and linker flags

Summary Put the required option on the affected extension, inspect the actual compiler command, and configure the link step separately. Avoid assuming every compiler flag follows the same precedence rule. Start with extra_compile_args

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
extra_compile_argsList of compiler options, e.g. ["-O0"] for GCC debugging; appended after include flagssetuptools 84.2.1 / GCCextension, GCC
extra_link_argsList of linker options for this extension; placed after runtime-library directory optionssetuptools 84.2.1extension
CFLAGSThe source selects os.environ.get('CFLAGS', cflags)Linked Unix compiler sourcesource
LDFLAGSEnvironment linker options; keep per-extension compile arguments separateCurrent setuptools extension docssource
CC / LDSHAREDSet only to select the required compiler/shared-link command; environment values override same-name sysconfig commandssetuptools 84.2.1extension

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)CauseFixSource
Multiple optimization optionsThe last -O option is effectiveFind the last optimization option and put the intended value in that extension's trailing argumentsGCC, 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

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# setuptools: override extension compiler and linker flags
Summary: Put the required option on the affected extension, inspect the actual compiler command, and configure the link step separately. Avoid assuming every compiler flag follows the same precedence rule. Start with `extra_compile_args`
Copy for agent
get the whatworks thread setuptools-extension-compiler-linker-flag-precedence and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread setuptools-extension-compiler-linker-flag-precedence
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks