How to provide C++ version when extending python

I want to make c++ code callable from python. 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

from distutils.core import setup, Extension

MOD = "ext"

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

    ext_modules = [module]

I’m using linux, if that matters.

>Solution :

You can pass compiler arguments as extra_compile_args so for example

module = Extension(
  sources = ["hello.cpp"],
  extra_compile_args = ["-std=c++20"]

Leave a Reply