boost-python - boost-python python3 不会将 str 转换为 std::string
问题描述
我试图公开一个非常简单的功能:
void f(const std::string &c) {
std::cout << c << std::endl;
}
def("f", &::f);
python2 工作正常,但是当我将代码与 python3 链接时,出现此错误:
import p
p.f('aaa')
Boost.Python.ArgumentError: Python argument types in
p.f(str)
did not match C++ signature:
f(std::string)
我注意到 python2 中存在的 stringobj.h 不再存在于 python3 中。
如果我用 f(char const*c) 替换 f(std::string) 一切都适用于 python2 和 python3
如何修复此错误?
解决方案
推荐阅读
- c# - 将 C# 代码转换为 LINQ C# 但列出添加相同项目
- javascript - 类型错误:无法读取未定义 JavaScript 的属性分析
- java - 是否可以创建 log.info 切入点?
- r - 更新 Picker Input,重用选中的数据
- linux - 如何在spec文件中获取rpm文件路径
- java - 无法解析片段中的方法“getIntent”
- mysql - 我如何让 mysql 返回 JSON 中的数组
- node.js - 如何以有效的方式代理来自我的 Node.js 应用程序的 GraphQL 请求?
- apache-kafka - Datadog 的 Kafka 集成 DD_KAFKA_CLIENT_PROPAGATION_ENABLED - Magic v1 不支持记录头
- python - Python Dash 核心组件 Graph() 与 Plotly Express