How to provide C++ version when extending python

Question:

I want to make c++ code callable from python.

https://docs.python.org/3/extending/ explains how to do this, but does not mention how to specify c++ version.

By default distutils calls g++ with a bunch of arguments, however does not provide the version argument.
Example of setup.py:

from distutils.core import setup, Extension

MOD = "ext"

module = Extension("Hello", sources = ["hello.cpp"])

setup(
    name="PackageName",
    version="0.01",
    description="desc",
    ext_modules = [module]
)

I’m using linux, if that matters.

Asked By: DiKetarogg

||

Answers:

You can pass compiler arguments as extra_compile_args so for example

module = Extension(
  "Hello",
  sources = ["hello.cpp"],
  extra_compile_args = ["-std=c++20"]
)
Answered By: Cory Kramer
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.