作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个我需要访问的某个库的 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 实例化为对象,并将我编写的接口(interface)中的 header 信息作为包装器传递:
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 的。所以我也无法解决这个问题......实际上我认为需要将路径传递给 Native.loadLibrary 函数作为参数来定位 dll。我将 dll 放在与 Java 类相同的路径中。这令人困惑,我怀疑也是错误的。
那么实例化 JNAerator 生成的接口(interface)的正确方法是什么?
最佳答案
您发布的 header 没有定义 Z3_config 是什么,它只说 DEFINE_TYPE(Z3_config);此 header 没有足够的信息来生成有效的绑定(bind)。清理 header ,删除所有 #ifdef 等,包括这些类型实际应该是什么,然后再次尝试生成代码。
关于java - 包装 C 头文件以将其与 dll 和 JNA(erator) 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135359/
我有一个我需要访问的某个库的 C 头文件。因此,在我读到人们最近推荐它之后,我使用 JNAerator 来完成无聊的代码转换。从我看来似乎相当可靠: public class Z3_apiLibrar
我是一名优秀的程序员,十分优秀!