Popularity
5.3
Growing
Activity
3.7
Declining
710
42
101

Code Quality Rank: L2
Programming language: Java
Tags: Native    
Latest version: v2.1.12

JNR alternatives and similar libraries

Based on the "Native" category

  • JNA

    8.9 6.9 L1 JNR VS JNA
    Work with native libraries without writing JNI. Also provides interfaces to common system libraries.
  • JavaCPP

    8.1 7.9 L1 JNR VS JavaCPP
    Provides efficient and easy access to native C++.

Do you think we are missing an alternative of JNR or a related project?

Add another 'Native' Library

README

jnr-ffi Build Status

jnr-ffi is a Java library for loading native libraries without writing JNI code by hand, or using tools such as SWIG.

Example

package helloworld;

import jnr.ffi.LibraryLoader;

public class HelloWorld {
    public static interface LibC {
        int puts(String s);
    }

    public static void main(String[] args) {
        LibC libc = LibraryLoader.create(LibC.class).load("c");

        libc.puts("Hello, World");
    }
}

Supported Types

All Java primitives are mapped simply to the equivalent C types.

  • byte - 8 bit signed integer
  • short - 16 bit signed integer
  • int - 32 bit signed integer
  • long - natural long (i.e. 32 bits wide on 32-bit systems, 64 bits wide on 64-bit systems)
  • float - 32 bit float
  • double - 64 bit float

The width and/or signed-ness of these basic types can be specified using one of the type alias annotations. e.g.

// Use the correct width for the result from getpid(3)
@pid_t long getpid();

// read(2) returns a signed long result, and its length parameter is an unsigned long
@ssize_t long read(int fd, Pointer data, @size_t long len);

In addition, the following Java types are mapped to a C pointer

  • String - equivalent to const char *
  • Pointer - equivalent to void *
  • Buffer - equivalent to void *