如果我在Ubuntu 20.04系统上运行cppyy v1.6.2中的以下测试脚本:
#!/usr/bin/python3
import cppyy
cppyy.cppdef("""
struct Test {
void test() const {
std::cout << std::is_same<int,double>::value << std::endl; // works
std::cout << std::is_same_v<int,double> << std::endl; // doesn't work
}
};
""");
tt = cppyy.gbl.Test()
tt.test()我得到以下错误消息:
input_line_21:5:21: error: no member named 'is_same_v' in namespace 'std'
std::cout << std::is_same_v<int,double> << std::endl; // doesn't work
~~~~~^
input_line_21:5:34: error: expected '(' for function-style cast or type construction
std::cout << std::is_same_v<int,double> << std::endl; // doesn't work
~~~^
Traceback (most recent call last):
File "./test.py", line 18, in <module>
tt = cppyy.gbl.Test()
AttributeError: <namespace cppyy.gbl at 0x45baf10> has no attribute 'Test'. Full details:
type object '' has no attribute 'Test'
'Test' is not a known C++ class
'Test' is not a known C++ template
'Test' is not a known C++ enum因为我在上面突出显示了这一行。其他的都没问题。
我知道std::is_same_v是C++17,但是在cppyy/cling网页上我找到了支持C++17的声明。怎么一回事?C++17在cppyy中不能工作吗?这能被配置吗?是否只有C++17的一个子集可用?
对于我的项目来说,C++17是非常重要的。
发布于 2021-10-26 20:20:38
为什么使用cppyy 1.6.2?最新版本是2.1.0。两者之间的一个很大的区别是后者的Clang下有一个更新的版本(后者也使得启用c++2a成为可能)。也就是说,对于我来说,1.6.2和2.1.0都不存在上述代码的问题,所以很可能是安装/构建问题。
首先,验证您的安装/构建中是否启用了C++17。例如:
$ python
>>> import cppyy
>>> cppyy.gbl.gInterpreter.ProcessLine('__cplusplus')如果启用了C++17,则结果应为201703或更高。
如果不是,重新安装,例如使用pip,假设你仍然想要1.6.2 (否则删除显式版本):
$ STDCXX=17 python -m pip install cppyy==1.6.2 --no-cache-dir --force-reinstall请注意,如果您的系统编译器(在构建CPyCppyy时使用)不支持C++17,它仍然会根据需要逐渐减少到C++14或C++11,即使使用STDCXX=17也是如此。
https://stackoverflow.com/questions/69729273
复制相似问题