Title: slim and alpine images record CXX=gcc since 3.14.6, breaking C++ extension builds (no libstdc++ link) · Issue #1131 · docker-library/python · GitHub
Open Graph Title: slim and alpine images record CXX=gcc since 3.14.6, breaking C++ extension builds (no libstdc++ link) · Issue #1131 · docker-library/python
X Title: slim and alpine images record CXX=gcc since 3.14.6, breaking C++ extension builds (no libstdc++ link) · Issue #1131 · docker-library/python
Description: Summary Since 3.14.6, the slim and alpine images record CXX=gcc and LDCXXSHARED="gcc -shared" in _sysconfigdata. setuptools links C++ extension modules with LDCXXSHARED, and gcc does not link libstdc++, so every C++ extension built from ...
Open Graph Description: Summary Since 3.14.6, the slim and alpine images record CXX=gcc and LDCXXSHARED="gcc -shared" in _sysconfigdata. setuptools links C++ extension modules with LDCXXSHARED, and gcc does not link libst...
X Description: Summary Since 3.14.6, the slim and alpine images record CXX=gcc and LDCXXSHARED="gcc -shared" in _sysconfigdata. setuptools links C++ extension modules with LDCXXSHARED, and gcc does not ...
Opengraph URL: https://github.com/docker-library/python/issues/1131
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"slim and alpine images record CXX=gcc since 3.14.6, breaking C++ extension builds (no libstdc++ link)","articleBody":"## Summary\n\nSince **3.14.6**, the `slim` and `alpine` images record `CXX=gcc` and `LDCXXSHARED=\"gcc -shared\"` in `_sysconfigdata`. setuptools links C++ extension modules with `LDCXXSHARED`, and `gcc` does not link libstdc++, so **every C++ extension built from an sdist inside these images produces a `.so` with no `DT_NEEDED` on `libstdc++.so.6`** and fails at import with an undefined C++ symbol.\n\nThis happens even when the user has installed `g++` themselves, because the wrong value is baked into `_sysconfigdata` at image build time.\n\n## Affected images\n\n```\n$ docker run --rm python:X python -c \"import sysconfig; print(sysconfig.get_config_var('CXX'), '|', sysconfig.get_config_var('LDCXXSHARED'))\"\n```\n\n| image | `CXX` | `LDCXXSHARED` | |\n|---|---|---|---|\n| `python:3.14.5` | `g++` | `g++ -shared` | ok |\n| `python:3.14.5-slim` | `g++` | `g++ -shared` | ok |\n| `python:3.14.5-alpine` | `g++` | `g++ -shared` | ok |\n| `python:3.13.15-slim` | `g++` | `g++ -shared` | ok |\n| `python:3.14.7` | `/usr/bin/g++` | `/usr/bin/g++ -shared` | ok |\n| `python:3.14.6-slim` | **`gcc`** | **`gcc -shared`** | **broken** |\n| `python:3.14.7-slim` | **`gcc`** | **`gcc -shared`** | **broken** |\n| `python:3.14.7-alpine` | **`gcc`** | **`gcc -shared -Wl,-z,stack-size=1048576`** | **broken** |\n\n3.14.3 and 3.14.4 are also fine; the change appears in 3.14.6. Reproduced on both `linux/amd64` and `linux/arm64`.\n\n## Reproduction\n\n`repro.sh`:\n\n```bash\nset -e\napt-get update -qq >/dev/null 2>&1\napt-get install -y -qq --no-install-recommends build-essential >/dev/null 2>&1\npip install -q setuptools >/dev/null 2>&1\nmkdir -p /t && cd /t\n\ncat > ext.cpp \u003c\u003c'CPP'\n#include \u003cPython.h>\n#include \u003cstdexcept>\nstatic PyObject* f(PyObject*, PyObject*) {\n try { throw std::runtime_error(\"boom\"); }\n catch (const std::exception& e) { return PyUnicode_FromString(e.what()); }\n}\nstatic PyMethodDef M[] = {{\"f\", f, METH_NOARGS, \"\"},{NULL,NULL,0,NULL}};\nstatic struct PyModuleDef mod = {PyModuleDef_HEAD_INIT, \"ext\", NULL, -1, M};\nPyMODINIT_FUNC PyInit_ext(void){ return PyModule_Create(&mod); }\nCPP\n\ncat > setup.py \u003c\u003c'PY'\nfrom setuptools import setup, Extension\nsetup(name=\"ext\", ext_modules=[Extension(\"ext\", [\"ext.cpp\"], language=\"c++\")],\n script_args=[\"build_ext\", \"--inplace\"])\nPY\n\npython setup.py >/dev/null 2>&1\necho -n \" DT_NEEDED libstdc++: \"; grep -aq \"libstdc++.so.6\" ext*.so && echo YES || echo NO\necho -n \" import: \"; python -c \"import ext; print('OK ->', ext.f())\" 2>&1 | tail -1\n```\n\nRun it in both images:\n\n```bash\nfor v in 3.14.5 3.14.7; do\n echo \"== python:$v-slim ==\"\n docker run --rm -v \"$PWD/repro.sh:/x.sh\" \"python:$v-slim\" bash /x.sh\ndone\n```\n\nResult — note that `build-essential`, which provides `g++`, is installed in **both** cases:\n\n```\n== python:3.14.5-slim ==\n DT_NEEDED libstdc++: YES\n import: OK -> boom\n== python:3.14.7-slim ==\n DT_NEEDED libstdc++: NO\n import: ImportError: /t/ext.cpython-314-x86_64-linux-gnu.so: undefined symbol: _ZNSt13runtime_errorD1Ev\n```\n\n## Real-world impact\n\nAny project that compiles a C++ extension from an sdist. In our case `cartopy`, which publishes no wheels and so is always compiled:\n\n```\nImportError: /app/.venv/lib/python3.14/site-packages/cartopy/trace.cpython-314-x86_64-linux-gnu.so:\nundefined symbol: _ZTINSt8ios_base7failureB5cxx11E\n```\n\nThis can stay hidden for a long time: with Docker layer caching the extension is only recompiled when an earlier layer changes, so an image keeps building successfully on a cached `.so` and then breaks on the first unrelated cache bust.\n\n## Likely cause\n\n`3.14/slim-trixie/Dockerfile` and `3.14/alpine*/Dockerfile` list `gcc` in their build dependencies but not `g++`, whereas `3.14/trixie/Dockerfile` inherits `g++` from `buildpack-deps:trixie`. That matches the table exactly: the two variants without `g++` at CPython build time are the two that are broken, and the full image is fine.\n\nThat has presumably always been true of the slim/alpine dependency lists, so the trigger looks like a change in how CPython's `configure` handles a missing `g++` between 3.14.5 and 3.14.6. 3.14.5 recorded the bare name `g++` regardless, which then resolved fine once the user installed it; 3.14.6+ appears to resolve it at configure time and fall back to `$CC` when it is absent. Consistent with that, the full image now records the absolute `/usr/bin/g++` where 3.14.5 recorded the bare `g++`.\n\n## Suggested fix\n\nAdd `g++` to the build dependencies for the `slim` and `alpine` variants so `configure` records a real C++ compiler. It is removed again with the rest of the build deps, so the runtime image size should be unaffected.\n\n## Workaround\n\nOverride the values in the build stage:\n\n```dockerfile\nENV CXX=\"g++\" LDCXXSHARED=\"g++ -shared\"\n```\n","author":{"url":"https://github.com/vtoupet","@type":"Person","name":"vtoupet"},"datePublished":"2026-08-28T09:06:28Z","url":"https://github.com/docker-library/python/issues/1131"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e9e13058-df22-6d09-311d-486fe6277fee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C1E:DDED5:11206A4:1781465:6AFEA1D1 |
| html-safe-nonce | ef299e6b567312f7f00b064d0358862d64979ebecd67956b79e98a4ce26ee008 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzFFOkRERUQ1OjExMjA2QTQ6MTc4MTQ2NTo2QUZFQTFEMSIsInZpc2l0b3JfaWQiOiIzMTMyOTQ1NTU2MzUxOTE4NTQ1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 38b2d40eb3818f2c8f21a7f20fbbc4633f236ed948fd868376e3c78b388eae95 |
| hovercard-subject-tag | issue:5276623177 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/docker-library/python/1131/issue_layout |
| twitter:image | https://opengraph.githubassets.com/657aade9d41d972febed01104e0a23b04bfedfd15c24c60fb24efbf8b8ab860c/docker-library/python/issues/1131 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/657aade9d41d972febed01104e0a23b04bfedfd15c24c60fb24efbf8b8ab860c/docker-library/python/issues/1131 |
| og:image:alt | Summary Since 3.14.6, the slim and alpine images record CXX=gcc and LDCXXSHARED="gcc -shared" in _sysconfigdata. setuptools links C++ extension modules with LDCXXSHARED, and gcc does not link libst... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vtoupet |
| hostname | github.com |
| expected-hostname | github.com |
| None | 95b2753c978240785d6cca00783c00a371b2d7d9879bb32e305170a1b19bd28e |
| turbo-cache-control | no-preview |
| go-import | github.com/docker-library/python git https://github.com/docker-library/python.git |
| octolytics-dimension-user_id | 7739233 |
| octolytics-dimension-user_login | docker-library |
| octolytics-dimension-repository_id | 21054928 |
| octolytics-dimension-repository_nwo | docker-library/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21054928 |
| octolytics-dimension-repository_network_root_nwo | docker-library/python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3f25273206cd841171bca0002261ae4c9757d934 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width