我正在尝试将其他人用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)
谷歌搜索,我意识到错误可能是由参数的类型引起的,而不是由数字引起的(这很令人困惑),但我仍然无法识别。我怀疑问题在于将字符串作为第一个参数传递,但不知道如何修复它(请记住,我几乎不知道c / c ++)。
答案 0 :(得分:2)
SWIG将字符串视为'char *'。你使用'unsigned char *'很可能会让人感到困惑。您可以将签名更改为“char *”或提供类型映射:
%typemap(in) unsigned char * = char*
答案 1 :(得分:2)
尝试:
%typemap(in) (unsigned char *) = (char *);
答案 2 :(得分:-1)
这可以通过修改第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)
祝你好运