Edit:
After better understanding the question & focusing on "dynamically" (without pre-compilation), I still hesitate to claim "it is impossible" ("impossible" is a very strong word/meaning ...like "always"/"never"), but I am very sure that this is not the standard routine of BridJ.
I can think of a dynamical solution with Bridj, but this would be very probably dependent from "JNAerator" and this in turn would be dependent from "JNA" (your starting position).
The original answer, describing the "standard routine" for "dynamically invoke any native function with BridJ" (involving code generation):
According to https://code.google.com/p/bridj/ and https://code.google.com/p/bridj/wiki/FAQ, you'll have to:
- Set up a bridJ project (java project + bridJ dependencies)
- Run the JNAerator (with bridJ output option) against your libs. This will generate Java files, which serve as "stubs/delegates" for your exported functions.
- These "stubs" can be referenced/used by your java code, and (should) invoke your libs.
Sample taken from "their Quickstart":
Original C++ code :
/// exported in test.dll / libtest.so / libtest.dylib
class MyClass {
public:
MyClass();
~MyClass();
virtual void virtualMethod(int i, float f);
void normalMethod(int i);
};
void getSomeCount(int* countOut);
...
void test() {
int count;
getSomeCount(&count);
MyClass t;
t.virtualMethod(count, 0.5f);
}
Translation + binding with BridJ :
(this is generated java code)
import org.bridj.*; // C interop and core classes
import org.bridj.ann.*; // annotations
import org.bridj.cpp.*; // C++ runtime
import static org.bridj.Pointer.*; // pointer factories such as allocateInt(), pointerTo(java.nio.Buffer), etc...
@Library("test")
public class TestLibrary {
static {
BridJ.register(); // binds all native methods in this class and its subclasses
}
public static class MyClass extends CPPObject {
@Virtual(0) // says virtualMethod is the first virtual method
public native void virtualMethod(int i);
public native void normalMethod(int i);
};
public static native void getSomeCount(Pointer<Integer> countOut);
public static void test() {
Pointer<Integer> pCount = allocateInt();
getSomeCount(pCount);
MyClass t = new MyClass();
t.virtualMethod(pCount.get(), 0.5f);
}
}
Hope this helps!