Java 致命错误:jni.h:没有那个文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19836848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:35:21  来源:igfitidea点击:

fatal error: jni.h: No such file or directory

javacinterfacenative

提问by anmi

I'm trying to recreate this tutorial on Windows: Java Native Interface (JNI)

我正在尝试在 Windows 上重新创建本教程: Java Native Interface (JNI)

When I try to compile it I get the following error:

当我尝试编译它时,出现以下错误:

fatal error: jni.h: No such file or directory

 #include <jni.h>

compilation terminated.

My command line is:

我的命令行是:

gcc -Wl,--add-stdcall-alias -IC:\Program_Files\Java\jdk1.7.0_45\include -IC:\Program_Files\Java\jdk1.7.0_45\include\win32 -shared -o hello.dll HelloJNI.c

I compile in the folder where all the files are.

我在所有文件所在的文件夹中编译。

I am sure that the file "jni.h" in this folder is located:

我确定此文件夹中的文件“jni.h”位于:

C:\Program Files\Java\jdk1.7.0_45\include

Does anyone know why the import statement does not work?

有谁知道为什么导入语句不起作用?

Thanks!

谢谢!

采纳答案by anmi

I got the answer:

我得到了答案:

I just need to use quotation marks, replace the backslash with slash and replace the underscores with spaces.

我只需要使用引号,用斜杠替换反斜杠并用空格替换下划线。

The command looks like this:

该命令如下所示:

gcc -Wl,--add-stdcall-alias -I"C:/Program Files/Java/jdk1.7.0_45/include" -I"C:/Program Files/Java/jdk1.7.0_45/include/win32" -shared -o hello.dll HelloJNI.c

gcc -Wl,--add-stdcall-alias -I"C:/Program Files/Java/jdk1.7.0_45/include" -I"C:/Program Files/Java/jdk1.7.0_45/include/win32" -共享 -o hello.dll HelloJNI.c

Thanks to all!!

谢谢大家!!

回答by Joni

Underscore is not the same as space. If jni.hreally is in the "program files" directory you should use this command:

下划线与空格不同。如果jni.h确实在“程序文件”目录中,则应使用以下命令:

gcc -Wl,--add-stdcall-alias -I "C:\Program Files\Java\jdk1.7.0_45\include" -I "C:\Program Files\Java\jdk1.7.0_45\include\win32" -shared -o hello.dll HelloJNI.c

gcc -Wl,--add-stdcall-alias -I "C:\Program Files\Java\jdk1.7.0_45\include" -I "C:\Program Files\Java\jdk1.7.0_45\include\win32" -共享 -o hello.dll HelloJNI.c