简体   繁体   English

扩展python时如何提供C++版本

[英]How to provide C++ version when extending python

I want to make c++ code callable from python.我想让 c++ 代码可以从 python 调用。

https://docs.python.org/3/extending/ explains how to do this, but does not mention how to specify c++ version. https://docs.python.org/3/extending/解释了如何做到这一点,但没有提到如何指定 c++ 版本。

By default distutils calls g++ with a bunch of arguments, however does not provide the version argument.默认情况下,distutils 使用一堆 arguments 调用 g++,但是不提供版本参数。 Example of setup.py: 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.如果重要的话,我正在使用 linux。

You can pass compiler arguments as extra_compile_args so for example您可以将编译器 arguments 作为extra_compile_args传递,例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM