JNI cannot detect __int64 on NetBeans(JNI 无法在 NetBeans 上检测到 __int64)
问题描述
我正在尝试编译一个本地库以从 java 中使用它(使用 JNI).我已按照本教程进行操作:https://cnd.netbeans.org/docs/jni/beginning-jni-win.html
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
当我尝试编译时,我有这个错误(见第 4 行):
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
[...]
我可以在 #include <jni.h>
之前添加 typedef long long __int64
来解决此错误,但我认为我正在做某事错了.
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.
代码如下:
头文件:
/* 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 具体类型
__int64
is Visual Studio specific type
使用标准类型,例如 int64_t 或 uint64_t.在 <cstdint>
中定义 C++,在
Use standard types like int64_t or uint64_t. Defined in <cstdint>
for C++ and in <stdint.h>
for C.
您的错误的确切解决方案可以在 JNI 常见问题中找到:
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.
所以你应该使用:
#define __int64 long long
或:
#include <stdint.h>
#define __int64 int64_t
这与您最初所做的非常相似
which is quite similar to what you have initially done
这篇关于JNI 无法在 NetBeans 上检测到 __int64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JNI 无法在 NetBeans 上检测到 __int64
基础教程推荐
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01