2

我正在尝试调用此函数

bool process(const short* pPCM, size_t num_samples, bool end_of_stream = false);

来自http://github.com/lastfm/Fingerprinter的 Last.FM FingerprintExtractor 开发的 fplib 部分

我试图通过 SWIG (2.0.8) 从 Ruby (1.9.2) 调用它。

到目前为止,这是我的 SWIG 文件

/* */
%define DOCSTRING
"This is a wrapper for The last.fm Fingerprint Extractor library."
%enddef
%module(docstring=DOCSTRING) FingerprintExtractor
%{
#include "../include/fplib/FingerprintExtractor.h"
%}
%include "typemaps.i"
%apply const short *INPUT { const short *pPCM };
%include "../include/fplib/FingerprintExtractor.h"

swig -c++ -ruby FingerprintExtractor.i 的输出

FingerprintExtractor.i:10: Warning 453: Can't apply (short const *INPUT). No typemaps are defined.

我认为我遇到的问题是围绕“const”。不幸的是,我是 C++ 和 SWIG 的新手。我知道“const”强制变量为常量,这在 C++ 中是一种很好的做法。但我不知道如何让 SWIG 打球。根据消息,我需要为“const short *”声明定义一个类型映射,但对于我来说,我无法弄清楚。

任何帮助弄清楚这一点将不胜感激。

我已经阅读了http://www.swig.org/Doc1.3/Ruby.html上的大量文档,遗憾的是这超出了我的技能范围,虽然它涵盖了指针、数组、常量、typedef 和 typemaps 方面我还没有能够弄清楚这一切与在声明为 const 时将指针传递给数组有关。我已经查看了 C++ 语言以了解对“const”的要求。我试图通过查看其他实现来进一步了解这种情况,当然我已经用谷歌搜索过了。没有足够具体的东西出现在我能理解的水平上。因此我请求帮助。

4

1 回答 1

2

尝试添加:

%包括“stdint.i”

下:

%包括“typemaps.i”

stdint.i 具有常见类型的类型定义,包括短。

于 2013-07-16T14:49:17.800 回答