我有一个指向我需要访问的某个库的C标头。所以我用JNAerator做了一些无聊的代码转换--在我读到最近人们推荐它之后。从我所看到的来看,似乎是相当可靠的:
public class Z3_apiLibrary implements Library {
public static final String JNA_LIBRARY_NAME = LibraryExtractor.getLibraryPath("z3_api", true, z3_api.Z3_apiLibrary.class);
public static final NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(JNA_LIBRARY_NAME, com.ochafik.lang.jnaerator.runtime.MangledFunctionMapper.DEFAULT_OPTIONS);
static {
Native.register(JNA_LIBRARY_NAME);
}
public static interface Z3_lbool {
public static final int Z3_L_FALSE = -1;
public static final int Z3_L_UNDEF = 0;
public static final int Z3_L_TRUE = 1;
};
public static interface Z3_symbol_kind {
public static final int Z3_INT_SYMBOL = 0;
public static final int Z3_STRING_SYMBOL = 1;
};完整的代码在我的GitHub上。
现在,我希望将dll作为对象实例化,并将来自我编写的接口的头信息作为包装器传递:
public class z3_Solver {
public static void main(String[] args) {
Z3_apiLibrary solver = (Z3_apiLibrary) Native.loadLibrary("z3", Z3_apiLibrary.class);
Z3_apiLibrary config = new Z3_apiLibrary.Z3_config(); // will not work!
}令我惊讶的是,这并不起作用。.Z3_config()是抽象的。mk_config是静态的和本机的。所以我也不能解决这个问题...实际上,我认为需要将路径作为参数传递给Native.loadLibrary函数来定位dll。我将dll放在与Java类相同的路径中。这是令人困惑的,我怀疑也是错误的。
那么实例化JNAerator生成的接口的正确方法是什么呢?
发布于 2011-05-26 18:10:49
您发布的标头没有定义什么是Z3_config,它只说明了DEFINE_TYPE(Z3_config);这个标头没有足够的信息来生成有效的绑定。清理头部,删除所有#ifdef等,包括这些类型实际应该是什么,然后再次尝试生成代码。
https://stackoverflow.com/questions/6135359
复制相似问题