JNI - "无法打开包含文件:'jni_md.h'" [英] JNI - "Cannot open include file: 'jni_md.h'"

查看:1282
本文介绍了JNI - "无法打开包含文件:'jni_md.h'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此示例程序的目的是叫原生C语言编写的方法。

This sample program is meant to call a native method written in C.

的Java code

class HelloWorld {

    private native void print();

    public static void main( String args[] ) {
        new HelloWorld().print();
    }

    static {
        System.loadLibrary("HelloWorld");
    }

}

写这个我编译的程序和生成后 JNI 风格的头文件。

生成的头文件是:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <C:\Program Files\Java\jdk1.7.0\include\jni.h>
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    print
 * Signature: ()V
 */
 JNIEXPORT void JNICALL Java_HelloWorld_print
 (JNIEnv *, jobject);

 #ifdef __cplusplus
 }
 #endif
 #endif

并用C语言编写的本地方法

#include <C:\Program Files\Java\jdk1.7.0\include\jni.h>
#include <C:\Program Files\Java\jdk1.7.0\include\win32\jni_md.h>
#include <stdio.h>
#include "HelloWorld.h"

JNIEXPORT void JNICALL Java_HelloWorld_print( JNIENv *env , jobject obj) {
    printf("Hello World!\n");
    return;
}

我得到的编译错误是致命错误C1083:无法打开包含文件:'jni_md.h:没有这样的文件或目录

此外我的编译器下划线 jobject OBJ 说,这个类没有存储类或说明。它强调 * ENV 预期')

Also my compiler underlines jobject obj saying that this class does not have storage class or specifier . It underlines *env saying expected a ')'.

为什么我得到这个错误?

Why do I get this error ?

推荐答案

我怀疑 jni.h 正在尝试的#include&LT; jni_md .H&GT; 中,然后失败,因为你没有添加它的位置include路径

I suspect that jni.h is trying to #include <jni_md.h>, which is then failing because you haven't added its location to your include path.

尝试增加这两​​个条目到您的C编译器的包括路径:

Try adding both of these entries to your C compiler's include path:


  • C:\\ Program Files文件\\的Java \\ jdk1.7.0 \\包含

  • C:\\ Program Files文件\\的Java \\ jdk1.7.0 \\包括\\ WIN32

  • C:\Program Files\Java\jdk1.7.0\include
  • C:\Program Files\Java\jdk1.7.0\include\win32

的win32 路径可能没有必要,取决于如何 jni.h 设置。

The win32 path might not be necessary, depending on how jni.h is set up.

这篇关于JNI - &QUOT;无法打开包含文件:'jni_md.h'&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆