0

I am trying to setup a JNI demo example and got stuck at exporting a library on Windows OS.

According to this tutorial, the following command should be executed:

gcc -o libctest.so -shared -I/path/to/jdk/headers ctest.c -lc

where the /path/to/jdk/headers refers to the directory that contains jni.h.

This is how invoke the command:

gcc -o ctest.dll -shared -I/"C:/Program Files/Java/jdk1.8.0_45/include" ctest.c -lc

and the result was:

jni.h: no such file or directory.
include jni.h

I have checked out this and this, which seems to suggest pretty much what I did.

The code:

#include <jni.h>
#include <stdio.h>

JNIEXPORT void JNICALL Java_HelloWorld_helloFromC
  (JNIEnv * env, jobject jobj)
{
    printf("Hello from C!\n");
}

How do I get around this error?

Community
  • 1
  • 1
John
  • 5,189
  • 2
  • 38
  • 62

1 Answers1

2

Have you tried with:

gcc -o ctest.dll -shared -I"C:\Program Files\Java\jdk1.8.0_45\include" ctest.c -lc

Note that after -I the slash character is not there anymore and the delimiter is set to backslash (the Windows delimiter).

dan
  • 13,132
  • 3
  • 38
  • 49
  • Wow i am silly :) Well that did get me around that error. It exploded with missing jndi_md.h but managed to resolve it with another -I to relevant directory. – John Nov 10 '15 at 15:31