我正在尝试编译一个本机库,以便在java(使用JNI)中使用它。我已经按照本教程: https://cnd.netbeans.org/docs/jni/beginning-jni-win.html
当我尝试编译时,我有这个错误(见第4行):
[...]
In file included from ../../Progra~2/Java/jdk1.8.0_91/include/jni.h:45:0,
from HelloWorldNative.h:3,
from HelloWorldNative.c:6:
../../Progra~2/Java/jdk1.8.0_91/include/win32/jni_md.h:34:9: error: unknown type name '__int64'
typedef __int64 jlong;
^
nbproject/Makefile-Debug.mk:66: recipe for target 'build/Debug/Cygwin-Windows/HelloWorldNative.o' failed
[...]
我可以在typedef long long __int64
之前添加#include <jni.h>
来解决此错误,但我认为有些事我做错了。
以下是代码:
HEADER FILE:
/* DO NOT EDIT THIS FILE - it is machine generated */
typedef long long __int64; // <============ Why do I need to do this?
#include <jni.h>
/* Header for class helloworld_Main */
#ifndef _Included_helloworld_Main
#define _Included_helloworld_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: helloworld_Main
* Method: nativePrint
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
SOURCE FILE:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
#include "HelloWorldNative.h"
JNIEXPORT void JNICALL Java_helloworld_Main_nativePrint
(JNIEnv *env, jobject _this){
}
答案 0 :(得分:1)
<cstdint>
是Visual Studio specific type
使用int64_t or uint64_t等标准类型。在<stdint.h>
中为C ++定义,在Your compiler might not like __int64 in jni_md.h. You should fix this by adding:
#ifdef FOOBAR_COMPILER
#define __int64 signed_64_bit_type
#endif
where signed_64_bit_type is the name of the signed 64 bit type supported by your compiler.
中为C。
您可以在JNI常见问题中找到错误的精确解决方案:
http://www.oracle.com/technetwork/java/jni-j2sdk-faq-141732.html
#define __int64 long long
所以你应该使用:
#include <stdint.h>
#define __int64 int64_t
或:
{{1}}
这与你最初的做法非常相似
答案 1 :(得分:0)
首先在构建工具中检查c编译器。更改该错误可以为我解决错误。