-
Notifications
You must be signed in to change notification settings - Fork 109
JNAerator (pronounce ‘generator’) is a tool that parses C / C++ & Objective-C sources (headers) and generates the corresponding BridJ, JNA and Rococoa Java interfaces.
This makes it easy to call large native libraries from Java.
By default, JNAerator creates ready-to-use compiled JARs with self-extractible native libraries. These JARs also contain the generated sources, which contain full JavaDoc that retains the comments from the original headers.
java -jar jnaerator.jar MyLib.dll MyLibHeader.h -mode StandaloneJar
will produce MyLib.jar
This is experimental and has big limitations, but simple cases should work:
java -jar jnaerator.jar MyLib.dll MyLibHeader.h -scanSymbols -mode StandaloneJar
will produce MyLib.jar
First make sure you compiled your solution in Release for both Win32 and Win64 targets, if needed.
java -jar jnaerator.jar MyLibHeader.sln -mode StandaloneJar will produce MySolution.jar
This is already done by default, provided that you add the paths to all needed libraries binaries to JNAerator's command line.
If you've opted for library bundling within the JNAerated JAR (see previous question), your libraries are shipped with your JAR and need not be pre-installed on the system. JNAerator will extract them in the directory .jnaerator/extractedLibraries under the user's home directory and will use them directly from there.
For a library with name 'foo' (which shared library files are named 'foo.dll', 'libfoo.so', 'libfoo.dylib'...), JNAerator's runtime will try the following PATH values, in order:
- Java preference 'library.foo' (modifiable with System.setPreference("library.foo", somePath))
- Environment variable 'FOO_LIBRARY' (set FOO_LIBRARY=c:\somewhereon windows, export FOO_LIBRARY=... on Unix)
- Java preference 'jna.library.path'
- Java preference 'java.library.path'
- Default system's shared library path environment variable : PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.
For more information please see JNA's documentation and CommandLineOptionsAndEnvironmentVariables.
For most commonly used public frameworks, you should simply download Rococoa and use it alone.
If you need frameworks not covered by Rococoa, wish to use private headers and / or frameworks or ObjectiveC libraries for which no headers are available, then you should use JNAerator :
java -jar jnaerator.jar -mode StandaloneJar -framework Framework1 -framework Framework2 lib1.dylib lib2.dylib...
There are quite a few of them : Command Line Options And Environment Variables
For now, JNA's users mailing list is THE place to be.
This appears to be a bug coming from its ANTLR parser, which does not react well to low-memory conditions. The parsing takes ages and seems to never end.
You can solve this by increasing the maximum memory allocated to the JVM:
java -Xmx1g -jar jnaerator.jar your-arguments-here
If this does not help, please file a bug with an execution trace you'll capture from jconsole.
Use the -noComp -noJar switches (see Command Line Options And Environment Variablesfor more options)
Please read Troubleshooting JNAeration
You can create a file with the extension .jnaerator that will contain all your command line arguments.
Please read JNAerator Files for more information.
Sure thing, you can chain multiple -library switches : -library Mine1 mine1.h libmine1.so -library Mine2 mine2.h libmine2.so -library Mine3 mine3.h libmine3.so
Here's a real-world example : OpenCV4Java's config.jnaerator file.
You just need to make sure that JNAerator's integrated preprocessor can resolve these includes.
JNAerator has a list of include paths that can be extended using the standard -I switch (which most if not all compilers accept) : adding "-Ipath" to the command line will add path to the include directories.
For instance, if one of your headers includes core/structs.h and you know that this header is located in /usr/myTestLib/include/core/structs.h, you need to add the following argument to the command line (or to your .jnaerator file) : -I/usr/myTestLib/include
Note that JNAerator should have default include paths for the most common system headers.
For more details on JNAerator's command line switches, see Command Line Options And Environment Variables.
The Issues section is here for that.