Files

27 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2019-12-01 23:54:45 +01:00
---
title: Modern C++ standards
---
2022-08-16 22:53:11 +01:00
# Modern C++ standards
Building Python wheels with modern C++ standards (C++11 and later) requires a few tricks.
2019-12-01 23:54:45 +01:00
2025-03-22 17:26:38 +01:00
## manylinux2014 and C++20
2019-12-01 23:54:45 +01:00
2025-03-22 17:26:38 +01:00
The past end-of-life `manylinux2014` image (based on CentOS 7) contains a version of GCC and libstdc++ that only supports C++17 and earlier standards.
`manylinux_2_28` are newer and support all C++ standards (up to C++20).
2019-12-01 23:54:45 +01:00
## macOS and deployment target versions
2019-12-01 23:54:45 +01:00
2025-04-13 07:16:55 +01:00
The [`MACOSX_DEPLOYMENT_TARGET` environment variable](platforms.md#macos-version-compatibility) is used to set the minimum deployment target for macOS.
2019-12-01 23:54:45 +01:00
2022-04-27 12:31:42 -04:00
However, to enable modern C++ standards, the deployment target needs to be set high enough (since older OS X/macOS versions did not have the necessary modern C++ standard library).
2019-12-01 23:54:45 +01:00
2024-10-08 10:26:58 -04:00
To get C++17 support, Xcode 9.3+ is needed, requiring at least macOS 10.13 on the build machine. To use C++17 library features and link against the C++ runtime library, set `MACOSX_DEPLOYMENT_TARGET` to `"10.13"` or `"10.14"` (or higher) - macOS 10.13 offers partial C++17 support (e.g., the filesystem header is in experimental, offering `#include <experimental/filesystem>` instead of `#include <filesystem>`); macOS 10.14 has full C++17 support. CPython 3.12+ require 10.13+ anyway.
However, if only C++17 compiler and standard template library (STL) features are used (not needing a C++17 runtime) it might be possible to set `MACOSX_DEPLOYMENT_TARGET` to a lower value, such as `"10.9"`. To find out if this is the case, try compiling and running with a lower `MACOSX_DEPLOYMENT_TARGET`: if C++17 features are used that require a more recent deployment target, building the wheel should fail.
For more details see https://en.cppreference.com/w/cpp/compiler_support, https://en.wikipedia.org/wiki/Xcode, and https://xcodereleases.com/: Xcode 10 needs macOS 10.13 and Xcode 11 needs macOS 10.14.