javadlljnajnaerator

Wrap C header file to use it with a dll and JNA(erator)


I have a C header to a certain library I need to access. So I used JNAerator to do the boring transitions of code - after I read that people recommend it these days. Seems to be quite solid from what I see:

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;
};

The complete code is at my GitHub.

Now I want to instantiate the dll as an object, and pass the header information from my written interface as a wrapper:

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!


   }

To my surprise this isn't working. .Z3_config() is abstract. mk_config is static and native. So I cannot resolve that either.... Actually I thought to need to pass the Path to the Native.loadLibrary function as a parameter to locate the dll. I put the dll in the same path as the Java class. Which is confusing and I suspect also wrong.

So what's the right way to instantiate that JNAerator generated interface?


Solution

  • The header you posted does not define what Z3_config is, it only says DEFINE_TYPE(Z3_config); This header does not have enough information to generate valid binding. Clean up the header, remove all #ifdef etc, include what those types actually should be, and then try generating code again.