拿出std_vector.我只处理一个文件,不能同时处理两个文件
SWIGs std_vector.i works on one file, but not both
我在android中使用SWIG将一堆c++代码转换为java。我有一个函数将从文件中读取数据,另一个将获取数据并对其进行处理。都使用
vector<complex<float> >
问题是,构建它会得到以下错误
[javac] do_something_with_data.work(return_data.read(num_samps));
[javac] ^
[javac] required: SWIGTYPE_p_vectorT_complexT_float_t_t
[javac] found: vector_complex_float
[javac] reason: actual argument vector_complex_float cannot be converted to SWIGTYPE_p_vectorT_complexT_float_t_t by method invocation conversion
[javac] 1 error
我发现有趣的是,它适用于一个,而不是另一个。我做错了什么?
这些是。i文件
/* turn this module into java using SWIG */
%module do_something_with_data
%{
#include <vector>
#include <complex>
#include "do_something_with_data.hh"
%}
/* Let's just grab the original header file here */
%include "std_vector.i"
namespace std {
%template(vector_complex_float) vector<complex<float> >;
}
/* boilerplate code */
%pragma(java) jniclasscode=%{
static {
try {
java.lang.System.loadLibrary("do_something_with_data");
} catch (UnsatisfiedLinkError e) {
java.lang.System.err.println("Native code library failed to import");
java.lang.System.exit(1);
}
}
%}
%include "do_something_with_data.hh"
和另一个。i文件
/* turn this module into java using SWIG */
%module return_data
%{
#include <vector>
#include <complex>
#include "return_data.hh"
%}
/* Let's just grab the original header file here */
%include "std_vector.i"
namespace std {
%template(vector_complex_float) vector<complex<float> >;
}
/* boilerplate code */
%pragma(java) jniclasscode=%{
static {
try {
java.lang.System.loadLibrary("return_data");
} catch (UnsatisfiedLinkError e) {
java.lang.System.err.println("Native code library failed to import");
java.lang.System.exit(1);
}
}
%}
%include "return_data.hh"
我用下面的脚本
编译这两个脚本swig -c++ -java -package do_something_with_data -outdir src/do_something_with_data -o jni/do_something_with_data/do_something_with_data.cc jni/do_something_with_data/do_something_with_data.i
swig -c++ -java -package return_data -outdir src/return_data -o jni/return_data/return_data_wrap.cc jni/return_data/return_data.i
我知道我已经给出了很多代码,但是对我来说添加函数的定义可能也很重要。这些都在类声明的。hh文件中。
int32 work(vector<complex<float> > &input_items);
和
vector<complex<float> > read(int num_samps);
提前感谢您的帮助
您需要告诉SWIG两个文件中的类是相同的。请参阅SWIG文档的文件导入部分,其中也引用了第15节以了解更多详细信息。这里,do_something_with_data
使用return_data
,所以在do_something_with_data.i
中加入%import "return_data.i"
。此外,您不需要重新定义向量模板。所以你的do_something_with_data.i
应该是:
/* turn this module into java using SWIG */
%module do_something_with_data
%{
#include <vector>
#include <complex>
#include "do_something_with_data.hh"
%}
%import "return_data.i"
/* boilerplate code */
%pragma(java) jniclasscode=%{
static {
try {
java.lang.System.loadLibrary("do_something_with_data");
} catch (UnsatisfiedLinkError e) {
java.lang.System.err.println("Native code library failed to import");
java.lang.System.exit(1);
}
}
%}
%include "do_something_with_data.hh"
我主要问了两个问题。首先,为什么类型不同,其次,我如何使它们相互配合。我两个都解决了。
首先,类型不同是因为.i文件包含的头文件中缺少一行。将"using namespace std;"放在所有包含的.hh文件中,允许下面的代码块工作。
namespace std {
%template(vector_complex_float) vector<complex<float> >;
}
问题的第二部分已经在上面回答了,尽管我使用了一种稍微不同的方法。我创建了一个。I文件,其中包含了我感兴趣的所有软件包。这导致了以下代码:
/* turn this module into java using SWIG */
%module er_java
%{
#include <vector>
#include <complex>
#include "read_data.hh"
#include "do_something_with_data.hh"
%}
/* Let's just grab the original header file here */
%include "std_vector.i"
%include "std_string.i"
namespace std {
%template(vector_complex_float) vector<complex<float> >;
%template(vector_float) vector<float>;
}
/* boilerplate code */
%pragma(java) jniclasscode=%{
static {
try {
java.lang.System.loadLibrary("read_data");
java.lang.System.loadLibrary("do_something_with_data");
} catch (UnsatisfiedLinkError e) {
java.lang.System.err.println("Native code library failed to import");
java.lang.System.exit(1);
}
}
%}
%include "read_data/read_data.hh"
%include "do_something_with_data/do_something_with_data.hh"
并使用下面的
行构建所有内容 swig -c++ -java -package er_java -outdir src/er_java -o jni/project/er_java_wrap.cc jni/swig_libs.i
只是不要忘记编译生成的换行。Android.mk
相关文章:
- 出色的文件处理能力
- C++中的文件处理:更新行
- 文件处理,eof() 定义
- C++网络 IO、文件处理和网络故障
- 如何使用自定义对象的序列化在 c++ 中编写自定义二进制文件处理程序
- ios::app 和 ios::noreplace 模式在文件处理中有什么区别?
- 我将如何在C++中文件处理对象(存储/导入)
- 如何为多个文件处理选择最佳的I/O策略
- read() 的参数类型,用于 c++ 中的文件处理
- STD :: FSTREAM文件处理重复使用的问题
- C 文件处理打开
- 将文件处理作为参数
- 如何在 C++ 中的文件处理中删除文件
- 文件处理I/O C 错误
- 在 c++ 的文件处理中什么是 tellg(),它是如何工作的?
- 循环的文件处理
- c++中数据文件处理中的分段错误
- 数据文件处理-查找文件中的字数
- 文件处理 - 错误:与 while 循环 (C++) 中的"运算符>>"不匹配(代码::块)
- 使用.rose(文件扩展)CPP的文件处理