尝试创建jni时出错:“\uu int64”未命名类型;你的意思是“\uu int64\t”

p1tboqfb  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(322)

我正试图按照本教程从安装了cygwin和mingw的windows 10计算机上构建jni项目:
https://www.baeldung.com/jni
我已经成功地创建了java文件 HelloWorldJNI.java 并生成了头文件 HelloWorldJNI.h .
“helloworldjni.java”文件:

public class HelloWorldJNI {

    static {
        System.loadLibrary("native");
    }

    public static void main(String[] args) {
        new HelloWorldJNI().sayHello();
    }

    // Declare a native method sayHello() that receives no arguments and returns void
    private native void sayHello();
}

生成的头文件“helloworldjni.h”:

/* DO NOT EDIT THIS FILE - it is machine generated */

# include <jni.h>

/* Header for class HelloWorldJNI */

# ifndef _Included_HelloWorldJNI

# define _Included_HelloWorldJNI

# ifdef __cplusplus

extern "C" {

# endif

/*
 * Class:     HelloWorldJNI
 * Method:    sayHello
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorldJNI_sayHello
  (JNIEnv *, jobject);

# ifdef __cplusplus

}

# endif

# endif

“HeloRoLDJNI.CPP”C++文件:


# include "HelloWorldJNI.h"

# include <stdio.h>

JNIEXPORT void JNICALL Java_HelloWorldJNI_sayHello(JNIEnv* env, jobject thisObject) {
    printf("Hello World");
}

我试图使用g++编译器编译“helloworldjni.cpp”,但收到了一系列错误:

C:\Users\Administrator\Desktop>g++ -c -I"C:\Program Files\Java\jdk-16.0.1\include" -I"C:\Program Files\Java\jdk-16.0.1\include\win32" HelloWorldJNI.cpp -o HelloWorldJNI.o
In file included from C:\Program Files\Java\jdk-16.0.1\include/jni.h:44,
                 from HelloWorldJNI.h:2,
                 from HelloWorldJNI.cpp:1:
C:\Program Files\Java\jdk-16.0.1\include\win32/jni_md.h:36:9: error: '__int64' does not name a type; did you mean '__int64_t'?
   36 | typedef __int64 jlong;
      |         ^~~~~~~
      |         __int64_t
In file included from HelloWorldJNI.h:2,
                 from HelloWorldJNI.cpp:1:
C:\Program Files\Java\jdk-16.0.1\include/jni.h:125:5: error: 'jlong' does not name a type; did you mean 'ulong'?
  125 |     jlong    j;
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:333:20: error: expected identifier before '*' token
  333 |     jlong (JNICALL *CallLongMethod)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:333:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  333 |     jlong (JNICALL *CallLongMethod)
      |                     ^~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:334:57: error: 'jlong' declared as function returning a function
  334 |       (JNIEnv *env, jobject obj, jmethodID methodID, ...);
      |                                                         ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:335:20: error: expected identifier before '*' token
  335 |     jlong (JNICALL *CallLongMethodV)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:335:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  335 |     jlong (JNICALL *CallLongMethodV)
      |                     ^~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:336:66: error: 'jlong' declared as function returning a function
  336 |       (JNIEnv *env, jobject obj, jmethodID methodID, va_list args);
      |                                                                  ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:337:20: error: expected identifier before '*' token
  337 |     jlong (JNICALL *CallLongMethodA)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:337:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  337 |     jlong (JNICALL *CallLongMethodA)
      |                     ^~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:338:72: error: 'jlong' declared as function returning a function
  338 |       (JNIEnv *env, jobject obj, jmethodID methodID, const jvalue *args);
      |                                                                        ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:415:20: error: expected identifier before '*' token
  415 |     jlong (JNICALL *CallNonvirtualLongMethod)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:415:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  415 |     jlong (JNICALL *CallNonvirtualLongMethod)
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:416:71: error: 'jlong' declared as function returning a function
  416 |       (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...);
      |                                                                       ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:417:20: error: expected identifier before '*' token
  417 |     jlong (JNICALL *CallNonvirtualLongMethodV)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:417:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  417 |     jlong (JNICALL *CallNonvirtualLongMethodV)
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:419:20: error: 'jlong' declared as function returning a function
  419 |        va_list args);
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:420:20: error: expected identifier before '*' token
  420 |     jlong (JNICALL *CallNonvirtualLongMethodA)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:420:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  420 |     jlong (JNICALL *CallNonvirtualLongMethodA)
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:422:26: error: 'jlong' declared as function returning a function
  422 |        const jvalue *args);
      |                          ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:466:20: error: expected identifier before '*' token
  466 |     jlong (JNICALL *GetLongField)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:466:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  466 |     jlong (JNICALL *GetLongField)
      |                     ^~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:467:50: error: 'jlong' declared as function returning a function
  467 |       (JNIEnv *env, jobject obj, jfieldID fieldID);
      |                                                  ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:486:52: error: 'jlong' has not been declared
  486 |       (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val);
      |                                                    ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:537:20: error: expected identifier before '*' token
  537 |     jlong (JNICALL *CallStaticLongMethod)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:537:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  537 |     jlong (JNICALL *CallStaticLongMethod)
      |                     ^~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:538:58: error: 'jlong' declared as function returning a function
  538 |       (JNIEnv *env, jclass clazz, jmethodID methodID, ...);
      |                                                          ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:539:20: error: expected identifier before '*' token
  539 |     jlong (JNICALL *CallStaticLongMethodV)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:539:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  539 |     jlong (JNICALL *CallStaticLongMethodV)
      |                     ^~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:540:67: error: 'jlong' declared as function returning a function
  540 |       (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args);
      |                                                                   ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:541:20: error: expected identifier before '*' token
  541 |     jlong (JNICALL *CallStaticLongMethodA)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:541:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  541 |     jlong (JNICALL *CallStaticLongMethodA)
      |                     ^~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:542:73: error: 'jlong' declared as function returning a function
  542 |       (JNIEnv *env, jclass clazz, jmethodID methodID, const jvalue *args);
      |                                                                         ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:579:20: error: expected identifier before '*' token
  579 |     jlong (JNICALL *GetStaticLongField)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:579:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  579 |     jlong (JNICALL *GetStaticLongField)
      |                     ^~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:580:51: error: 'jlong' declared as function returning a function
  580 |       (JNIEnv *env, jclass clazz, jfieldID fieldID);
      |                                                   ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:599:53: error: 'jlong' has not been declared
  599 |       (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value);
      |                                                     ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:661:5: error: 'jlong' does not name a type; did you mean 'ulong'?
  661 |     jlong * (JNICALL *GetLongArrayElements)
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:679:39: error: 'jlong' has not been declared
  679 |       (JNIEnv *env, jlongArray array, jlong *elems, jint mode);
      |                                       ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:696:63: error: 'jlong' has not been declared
  696 |       (JNIEnv *env, jlongArray array, jsize start, jsize len, jlong *buf);
      |                                                               ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:713:69: error: 'jlong' does not name a type; did you mean 'ulong'?
  713 |       (JNIEnv *env, jlongArray array, jsize start, jsize len, const jlong *buf);
      |                                                                     ^~~~~
      |                                                                     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:757:37: error: 'jlong' has not been declared
  757 |        (JNIEnv* env, void* address, jlong capacity);
      |                                     ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:760:20: error: expected identifier before '*' token
  760 |     jlong (JNICALL *GetDirectBufferCapacity)
      |                    ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:760:21: warning: 'stdcall' attribute only applies to function types [-Wattributes]
  760 |     jlong (JNICALL *GetDirectBufferCapacity)
      |                     ^~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:761:33: error: 'jlong' declared as function returning a function
  761 |        (JNIEnv* env, jobject buf);
      |                                 ^
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1004:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1004 |     jlong CallLongMethod(jobject obj, jmethodID methodID, ...) {
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1012:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1012 |     jlong CallLongMethodV(jobject obj, jmethodID methodID,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1016:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1016 |     jlong CallLongMethodA(jobject obj, jmethodID methodID,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1196:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1196 |     jlong CallNonvirtualLongMethod(jobject obj, jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1206:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1206 |     jlong CallNonvirtualLongMethodV(jobject obj, jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1211:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1211 |     jlong CallNonvirtualLongMethodA(jobject obj, jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1304:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1304 |     jlong GetLongField(jobject obj, jfieldID fieldID) {
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1338:23: error: 'jlong' has not been declared
 1338 |                       jlong val) {
      |                       ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1463:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1463 |     jlong CallStaticLongMethod(jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1472:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1472 |     jlong CallStaticLongMethodV(jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1476:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1476 |     jlong CallStaticLongMethodA(jclass clazz,
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1554:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1554 |     jlong GetStaticLongField(jclass clazz, jfieldID fieldID) {
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1589:25: error: 'jlong' has not been declared
 1589 |                         jlong value) {
      |                         ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1683:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1683 |     jlong * GetLongArrayElements(jlongArray array, jboolean *isCopy) {
      |     ^~~~~
      |     ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1719:35: error: 'jlong' has not been declared
 1719 |                                   jlong *elems,
      |                                   ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1755:53: error: 'jlong' has not been declared
 1755 |                             jsize start, jsize len, jlong *buf) {
      |                                                     ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1788:35: error: 'jlong' does not name a type; did you mean 'ulong'?
 1788 |                             const jlong *buf) {
      |                                   ^~~~~
      |                                   ulong
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1851:48: error: 'jlong' has not been declared
 1851 |     jobject NewDirectByteBuffer(void* address, jlong capacity) {
      |                                                ^~~~~
C:\Program Files\Java\jdk-16.0.1\include/jni.h:1857:5: error: 'jlong' does not name a type; did you mean 'ulong'?
 1857 |     jlong GetDirectBufferCapacity(jobject buf) {
      |     ^~~~~
      |     ulong

如何解决编译问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题