Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string arguments are not recognized by SWIG

Tags:

c++

string

swig

I have a frustrating problem which got me spend a lot of time dealing with it but I did not find any solution.

I want to use C++ class in PHP with SWIG. I generated my shared object and it works fine for some methods but I've got this error whenever I call the methods with string arguments as their input:

Fatal error: Type error in argument 2 of PKI_Buf_initHex. Expected SWIGTYPE_p_std__string

PKI_Buf_initHex is the name of the wrapper class which SWIG made automatically. In my C++ code I declare initHex method as:

int initHex(const string x) 
{..}

I included typemaps.i and std_string.i in my interface file but I got the same error message.

I truly would appreciate if anyone can help me with this issue.

like image 483
A23149577 Avatar asked Dec 02 '22 21:12

A23149577


1 Answers

You need to have:

%include <std_string.i>

Early enough in the SWIG interface (i.e. before std::string is first seen).

like image 105
Flexo Avatar answered Dec 04 '22 11:12

Flexo