17

While executing gcc command on ubuntu for generating .a or .so file for JNI, getting below error for both openjdk 8 / oraclejdk8.

$gcc -I/usr/lib/jvm/java-8-openjdk-amd64/include -c MainImpl1.c -o MainImpl1.o

In file included from MainImpl1.c:1:0:
/usr/lib/jvm/java-8-openjdk-amd64/include/jni.h:45:20: fatal error: jni_md.h: No such file or directory
 #include "jni_md.h"
                ^
compilation terminated.

$gcc -I/usr/lib/jvm/java-8-oracle/include -c MainImpl1.c -o MainImpl1.o

In file included from MainImpl1.c:1:0:
/usr/lib/jvm/java-8-oracle/include/jni.h:45:20: fatal error: jni_md.h: No such file or directory
 #include "jni_md.h"
                ^
compilation terminated.

I have given example for generating .a file, but same issue observed for .so file generation also.

But same gcc command works for openjdk7/oraclejdk7.

What is the issue here?

Mathieu
  • 8,840
  • 7
  • 32
  • 45
Manjunath
  • 185
  • 1
  • 1
  • 6

2 Answers2

32

I don't think you added the include directory that includes jni_md.h which is platform dependent.

Try

$gcc -I/usr/lib/jvm/java-8-openjdk-amd64/include -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux -c MainImpl1.c -o MainImpl1.o

or

$gcc -I/usr/lib/jvm/java-8-oracle/include -I/usr/lib/jvm/java-8-oracle/include/linux -c MainImpl1.c -o MainImpl1.o

If you don't know where jni_md.h is, use find:

find / -name jni_md.h 2> /dev/null
user438383
  • 5,716
  • 8
  • 28
  • 43
Mathieu
  • 8,840
  • 7
  • 32
  • 45
  • Depending on your preference, sometimes it's nicer to [add the include directories globally](https://stackoverflow.com/a/558819/1509695) after finding them, like if you're building someone else's project without wanting to fiddle their make files. – matanster Jun 13 '18 at 08:24
1

for “jni_md.h” No Such file or directory Error include below path with gcc:

-I/usr/lib/jvm/java-8-oracle/include/include/linux

for “jni.h” No Such file or directory Error include below path with gcc:

-I/usr/lib/jvm/java-8-oracle/include/include
Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25