Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

java - JNI cannot detect __int64 on NetBeans

I'm trying to compile a native library to use it from java (with JNI). I have followed this tutorial: https://cnd.netbeans.org/docs/jni/beginning-jni-win.html

The error

When I try to compile, I have this error (see line 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
[...]

I can solve this error adding a typedef long long __int64 before the #include <jni.h> but I assume that there is something that I'm doing wrong.

The code

Here is the code:

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){

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

__int64 is Visual Studio specific type

Use standard types like int64_t or uint64_t. Defined in <cstdint> for C++ and in <stdint.h> for C.


Exact solution to your error can be found in JNI faq:

http://www.oracle.com/technetwork/java/jni-j2sdk-faq-141732.html

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.

so you should use:

#define __int64 long long

or:

#include <stdint.h>
#define __int64 int64_t

which is quite similar to what you have initially done


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...