简体   繁体   中英

Swig unable to convert byte objectof python3 to std::string

I am trying to interface python3 with C++ using SWIG and it keeps throwing the following error

>> 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'**

Below are the attached files:

ipc.i file

%module ipc

%begin %{
    #define SWIG_PYTHON_STRICT_BYTE_CHAR
    #include "ipc.h"    
%}

%include std_string.i
%include stl.i
%include "ipc.h"

ipc.h file

#include<string>

extern int createQueue();
extern bool sendMessage(int, std::string);
extern std::string receiveMessage(int);
extern bool removeQueue(int);

Command used to build

>> 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后得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM