Search code examples
javacjava-native-interfaceclionautotools

Clion, Autotools and JNI


I'm trying to setup a little JNI demo with Autotools using the Clion IDE. The problem is: I don't know how to tell Autotools to include jni.h. Also Clion does not resolve the #include <jni.h>.

This is the bare minimun example I'd like you to tell me how to fix demo.


Solution

  • The $JAVA_HOME must be set.

    The fixed configure.ac looks like this:

    AC_INIT([helloworld], [0.1], [maintainer@example.com])
    AX_JNI_INCLUDE_DIR
    for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
    do
        CFLAGS="$CFLAGS -I$JNI_INCLUDE_DIR"
    done
    AM_INIT_AUTOMAKE
    AC_PROG_CC
    AC_CONFIG_FILES([Makefile])
    AC_OUTPUT
    

    CLion will then include the jni.h correctly.