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

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

问题描述

此示例程序旨在调用用 C 编写的 native 方法.

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

Java 代码

class HelloWorld {

    private native void print();

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

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

}

写完之后我编译了程序并生成了一个JNI风格的头文件.

After writing this i compiled the program and generated a JNI style header file.

生成的头文件是:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <C:Program FilesJavajdk1.7.0includejni.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 FilesJavajdk1.7.0includejni.h>
#include <C:Program FilesJavajdk1.7.0includewin32jni_md.h>
#include <stdio.h>
#include "HelloWorld.h"

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

我在编译时遇到的错误是 fatal error C1083: Cannot open include file: 'jni_md.h': No such file or directory

The error I get on compiling is fatal error C1083: Cannot open include file: 'jni_md.h': No such file or directory

我的编译器也在 jobject obj 下划线,说 这个类没有存储类或说明符.它在 *env 下划线,表示 expected a ')'.

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 ,其中然后失败,因为您没有将其位置添加到您的包含路径中.

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 FilesJavajdk1.7.0include
  • C:Program FilesJavajdk1.7.0includewin32

win32 路径可能不是必需的,具体取决于 jni.h 的设置方式.

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

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

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