如何让 cython 使用 c++20 编译器?

问题描述 投票:0回答:1

我尝试在 C++20 中使用 std 的一些功能,但是当我尝试使用 Cython 编译时出现错误。

%%cython -a -+

from libcpp.bit cimport popcount
print(popcount(5))

标准输出的内容: _cython_magic_8a7cc06c3f4134f8362279784510a3a14b752950.cpp
的内容仅适用于 C++20 或更高版本。

当我在 Visual Studio 中运行类似的 C++ 程序时,它工作得很好。

#include <iostream>
#include <bit>

int main()
{
    std::cout << std::popcount((unsigned int) 7);
}

3

如何查看我正在使用的编译器,或者如何将其设置为使用 c++20 的编译器?

cython
1个回答
0
投票

您需要使用

-std=c++20
标志
cythong magic
参数向编译器传递一个标志以启用 c++20、gcc 的
/std=c++20
或 msvc 的 -c

%%cython -c=-std=c++20 --cplus

from libcpp.bit cimport popcount
print(popcount(<unsigned long>(5)))

这适用于使用 gcc 的 colab,对于使用 msvc 的 Windows,您必须使用

/std=c++20
来代替。

© www.soinside.com 2019 - 2024. All rights reserved.