2016-04-25 64 views
1

我試圖編譯一個本地庫以使用它從java(與JNI)。我按照這個教程: https://cnd.netbeans.org/docs/jni/beginning-jni-win.htmlJNI無法檢測到NetBeans上的__int64

錯誤

當我嘗試編譯,我有這樣的錯誤(見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>但我認爲有什麼我做錯了。

代碼

下面是代碼:

頭文件:

/* 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 

源文件:

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

} 

回答

1

__int64是Visual Studio的specific type

使用標準類型如int64_t or uint64_t。定義在<cstdint>用於C++和<stdint.h>爲C.


到您的錯誤精確的解決方案可以在JNI常見問題解答中找到:

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. 

所以你應該使用:

#define __int64 long long 

或者:

#include <stdint.h> 
#define __int64 int64_t 

這是相當類似於您已經初步完成

+0

我試圖添加一個'#包括'前'的#include ',但它不工作。 – Dan

+0

@丹看到我的編輯,實際上你最初做的是可接受的解決方案 - 至少oracle建議這樣做。 – marcinj