我正在尝试包装其他人用swig编写的C ++类(我们称其为“垃圾邮件”),以将其公开给Python。解决了几个问题后,我能够在python中导入模块,但是当我尝试创建此类的对象时,出现以下错误:
foo = Spam.Spam('abc',3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Spam.py", line 96, in __init__
this = _Spam.new_Spam(*args)
NotImplementedError: Wrong number of arguments for overloaded function 'new_Spam'.
Possible C/C++ prototypes are:
Spam(unsigned char *,unsigned long,bool,unsigned int,SSTree::io_action,char const *)
Spam(unsigned char *,unsigned long,bool,unsigned int,SSTree::io_action)
Spam(unsigned char *,unsigned long,bool,unsigned int)
Spam(unsigned char *,unsigned long,bool)
Spam(unsigned char *,unsigned long)
[Google搜索,我意识到该错误可能是由参数的类型而不是数字引起的(这很令人困惑),但是我仍然无法确定。我怀疑问题出在传递字符串作为第一个参数,但不知道如何解决它(请记住,我几乎不了解c / c ++)。
SWIG将字符串视为'char *'。您对'unsigned char *'的使用极有可能使您感到困惑。您可以将签名更改为'char *'或提供一个typemap:
%typemap(in) unsigned char * = char*
尝试使用:
%typemap(in) (unsigned char *) = (char *);
这可以通过修改第100到110行来解决
self.source = uhd_receiver(options.args, symbol_rate,
options.samples_per_symbol,
options.rx_freq,
options.rx_gain, options.spec, options.antenna,
options.verbose)
self.sink = uhd_transmitter(options.args, symbol_rate,
options.samples_per_symbol,
options.tx_freq,
options.tx_gain, options.spec, options.antenna,
options.verbose)
至以下
self.source = uhd_receiver(options.args, symbol_rate,
options.samples_per_symbol,
options.rx_freq,
----------> options.lo_offset,
options.rx_gain, options.spec, options.antenna,
----------> options.clock_source,
options.verbose)
self.sink = uhd_transmitter(options.args, symbol_rate,
options.samples_per_symbol,
options.tx_freq,
----------> options.lo_offset,
options.tx_gain, options.spec, options.antenna,
----------> options.clock_source,
options.verbose)
祝你好运