首页 > 解决方案 > swig 2 编组到 std::vector& 从 java 到 c++

问题描述

这是我所拥有的:

%module FacadeInterface

%{
#include <Facade.h>
#include <boost/filesystem/path.hpp>
%}

%typemap(jni) boost::filesystem::path "jstring"
%typemap(jstype) boost::filesystem::path "java.io.File"
%typemap(jtype) boost::filesystem::path "String"
%typemap(javain) boost::filesystem::path "$javainput.toString()"
%typemap(in) boost::filesystem::path (boost::filesystem::path tmp) {
  const char *str = JCALL2(GetStringUTFChars, jenv, $input, 0);
  tmp = str;
  $1 = &tmp;
  JCALL2(ReleaseStringUTFChars, jenv, $input, str);
}

%include "Facade.h"

%include <std_vector.i>
%template(PathsVector) std::vector<boost::filesystem::path>;

这是 Facade.h 的内容

bool run(const std::vector<boost::filesystem::path> &plyFiles);

编译java源代码时出现以下错误:

/root/build/src/main/com/facade/PathsVector.java:71: error: incompatible types: String cannot be converted to long
    return new SWIGTYPE_p_boost__filesystem__path(FacadeInterfaceJNI.PathsVector_get(swigCPtr, this, i), false);

标签: javac++booststlswig

解决方案


推荐阅读