首页 > 解决方案 > 尝试使用 boost.python 从 python 将参数传递给 c++ 函数

问题描述

我正在尝试从 python 运行我的 c++ 应用程序。我已经设置了 boost.python 来允许我这样做;但是,我试图调用的 c++ 函数需要我在构建之前输入到 Visual Studio 的控制台参数。现在我有这个来自 python 的可调用对象,我很想通过 python 端传递这些参数。

我试图通过将参数输入 python 函数来输入它,但它存在转换问题。

这是错误消息: Boost.Python.ArgumentError: Python argument types in cplusplus.function(int, str, str, str, str) did not match C++ signature: function(int, char * __ptr64 * __ptr64)

如果有一种方法可以将字符串转换为 char* __ptr64 那就太好了。或者,如果有一种自动方式,那就更好了。

使用 python 3.7 visual studio 16.3 和最新的 boost(1.71)。我很乐意提供的任何其他信息

这是我的带参数的 c++ 函数声明:int notmain(int argc, char* argv[]) {

而python方面调用它:( print (cplusplus.function(Port, Server, user, pass, request)) 端口是一个int,其余的是字符串。)

对此的任何建议/见解将不胜感激,谢谢!

布雷迪

标签: pythonc++boostboost-python

解决方案


推荐阅读