在 android ndk 中,当我使用由辅助工具 javah
生成的头文件时,它工作正常。但是当我创建一个带有 .h 扩展名的普通文件并包含 jni.h
和任何其他所需的头文件时,我无法使用包含的头文件中的类型或关键字或任何函数,它总是显示我遇到“Type 'whatever' 无法解决”,而同样的事情我可以在机器生成的头文件中使用 javah
工具无缘无故地做。
尽管我在 C/C++ General -> Paths and Symbols ->Include 中包含了 arm 平台库。它一直向我显示此错误。
考虑以下代码。
#include "store.h"
#include <jni.h>
#include <stdint.h>
#include <pthread.h>
#ifndef _STOREWATCHER_H_
#define _STOREWATCHER_H_
#define SLEEP_DURATION 5
#define STATE_OK 0
#define STATE_KO 1
#ifdef __cplusplus
extern "C" {
#endif
typedef struct{
Store* mStore;
JavaVM* mJavaVM;
jobject mStoreFront;
pthread_t mThread;
int32_t mState;
}StoreWatcher;
#ifdef __cplusplus
}
#endif
#endif
它在这段代码中向我展示了 Store
、JavaVM
、jobject
、pthread_t
无法解析.请帮助我。
我们将不胜感激。
最佳答案
在 C 中,与 Java 不同,您有名称类似于 storewatcher.c
的文件和名称类似于 storewatcher.h
的文件。 .h
文件不会自行编译,您必须在一个或多个 .c
文件中为 使用
文件被编译器识别,例如#include
指令。 h
#include "storewatcher.h"
关于android - 类型无法在 ndk 中解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171212/