2016-04-25 4 views
1

Я пытаюсь скомпилировать родную библиотеку, чтобы использовать ее из java (с JNI). Я следовал за этот учебник: https://cnd.netbeans.org/docs/jni/beginning-jni-win.htmlJNI не может обнаружить __int64 на NetBeans

Ошибка

При попытке компиляции, я эту ошибку (см линия 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 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. 

так что вы должны использовать:

#define __int64 long long 

или:

#include <stdint.h> 
#define __int64 int64_t 

, которая очень похожа на то, что вы изначально сделали

+0

Я пытался добавить '#include ' до '#include ', но он не работает. – Dan

+0

@ Дай видеть мое редактирование, действительно то, что вы сделали изначально, было бы приемлемым решением - по крайней мере, оракул предлагает это сделать. – marcinj