Build status for all platforms: Commercial support:
This directory contains the JavaCPP Presets module for:
- libffi 3.4.2 https://sourceware.org/libffi/
Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.
Java API documentation is available here:
Here is a simple example of libffi ported to Java from the "Simple Example" in this file:
We can use Maven 3 to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the pom.xml
and SimpleExample.java
source files below, simply execute on the command line:
$ mvn compile exec:java
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.libffi</groupId>
<artifactId>simpleexample</artifactId>
<version>1.5.6</version>
<properties>
<exec.mainClass>SimpleExample</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>libffi-platform</artifactId>
<version>3.4.2-1.5.6</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>.</sourceDirectory>
</build>
</project>
import org.bytedeco.javacpp.*;
import org.bytedeco.libffi.*;
import static org.bytedeco.libffi.global.ffi.*;
public class SimpleExample {
static Pointer puts = Loader.addressof("puts");
public static void main(String[] a) {
ffi_cif cif = new ffi_cif();
PointerPointer<ffi_type> args = new PointerPointer<>(1);
PointerPointer<PointerPointer> values = new PointerPointer<>(1);
PointerPointer<BytePointer> s = new PointerPointer<>(1);
LongPointer rc = new LongPointer(1);
/* Initialize the argument info vectors */
args.put(0, ffi_type_pointer());
values.put(0, s);
/* Initialize the cif */
if (ffi_prep_cif(cif, FFI_DEFAULT_ABI(), 1,
ffi_type_sint(), args) == FFI_OK)
{
s.putString("Hello World!");
ffi_call(cif, puts, rc, values);
/* rc now holds the result of the call to puts */
/* values holds a pointer to the function's arg, so to
call puts() again all we need to do is change the
value of s */
s.putString("This is cool!");
ffi_call(cif, puts, rc, values);
}
System.exit(0);
}
}