Swig无法将python3的字节对象转换为std::string
Swig unable to convert byte objectof python3 to std::string
我正在尝试使用SWIG将python3与C++接口,它不断抛出以下错误
>> ipc.sendMessage(q, b'qwe')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: in method 'sendMessage', argument 2 of type 'std::string'**
以下是所附文件:
ipc.i文件
%module ipc
%begin %{
#define SWIG_PYTHON_STRICT_BYTE_CHAR
#include "ipc.h"
%}
%include std_string.i
%include stl.i
%include "ipc.h"
ipc.h文件
#include<string>
extern int createQueue();
extern bool sendMessage(int, std::string);
extern std::string receiveMessage(int);
extern bool removeQueue(int);
用于构建的命令
>> swig -c++ -python ipc.i
>> g++ -fpic -c ipc.h ipc_wrap.cxx ipc.cpp -I/usr/include/python3.5
>> gcc -shared ipc_wrap.o ipc.o -o _ipc.so -lstdc++
SWIG 3.0.8出现问题,更新到3.0.10后问题得到解决。
相关文章:
- 将无符号char*转换为std::istream*C++
- 可以有效地转换 std::any 与 std::any_cast
- 尝试转换 std::chrono::d uration 会导致"rep cannot be a duration"编译错误
- 封送处理 - 转换 std::向量<char>到字符串^ 反之亦然
- 在 C++ 中转换 std::string,使其可以是 C# 中的 byte[]
- 转换 std::vector<T> 为 char *
- 转换std ::绑定到功能指针
- 强制转换 std::vector 的所有成员
- 无法转换'std::string{又名std::basic_string<char>}'到&
- 转换std::string到cv::Mat对象
- 转换std::chrono::system_clock::time_point::min()为字符串时,无效空指针错误
- 简单的模板化函数,用于转换 std::vectors - "illegal use of this type as an expression"
- Const转换std容器
- 如何强制转换std::make_unique,以便可以使用在类中声明的函数
- 如何向下转换std::shared_ptr
- 转换 std::vector<uint8_t> 为 QImage
- 使用std::dynamic_pointer_cast向上转换std::shared_ptr
- 如何转换std::vector<无符号字符>到向量<char>而无需复制
- 正在强制转换std::pair
const&T1 const, T2>const&安全的 - 如何在boost.python中转换std::string*