java - JNI 无法在 NetBeans 上检测到 __int64

标签 java c++ c netbeans java-native-interface

我正在尝试编译一个 native 库以从 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> 之前但我认为我做错了什么。

代码

代码如下:

头文件:

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

}

最佳答案

__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

这与您最初所做的非常相似

关于java - JNI 无法在 NetBeans 上检测到 __int64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36846746/

相关文章:

java - 二维数组长度错误

c++ - 复制/分配 STL 模板,std::less 和 std:greater

我们可以更改指针指向的字符串字符吗?

c - 将 C 库与 Swift 结合使用(多指针及所有)

c - 一个只调用另一个函数的函数会减慢速度吗?

java - 读取对象文件而不出现 EOFException

java - 更新表会删除jsp页面中未绑定(bind)的列中的数据

java - 更改向上箭头颜色后标记为私有(private)警告

c++ - Assimp 对现有 aiVector3D 的访问冲突

c++ - 在 C++ 中,返回指向非常量对象的指针的 const 方法是否被认为是不好的做法?