SWIG不能识别字符串参数 [英] string arguments are not recognized by SWIG

查看:680
本文介绍了SWIG不能识别字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个令人沮丧的问题,我花了很多时间处理它,但我没有找到任何解决方案。



我想在PHP中使用c ++类与SWIG。我生成了我的共享对象,它的工作正常的一些方法,但是我有这个错误,当我调用的方法与字符串参数作为他们的输入:



致命错误:类型 PKI_Buf_initHex 的参数2中的错误。预期 SWIGTYPE_p_std__string



PKI_Buf_initHex 是包装类名称SWIG自动生成。在我的C ++代码中,我将 initHex 方法声明为:

  int initHex const string x)
{..}

我包括typemaps.i和std_string.i在我的界面文件,但我有相同的错误消息。



我真的很感激,如果有人可以帮助我这个问题。

 %include< std_string。 i。 

在SWIG界面中足够早(即 std :: string 首先出现)。


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 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.

解决方案

You need to have:

%include <std_string.i>

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

这篇关于SWIG不能识别字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆