2

当我试图在我的机器上编译我的示例本机 (cpp) 代码时,我遇到了这些错误。我正在尝试在 cygwin 的 NDK 的帮助下编译本机代码。

我收到以下错误,我尝试添加 LDFLAGS 但仍然收到相同的错误 LOCAL_LDLIBS := -llog

sh-4.1$ /cygdrive/c/Android/android-ndk-r6/ndk-build  
Compile++ thumb  : JNIExampleInterface <= JNIExampleInterface.cpp  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:5:44: error: android_runtime/AndroidRuntime.h: No such file or directory  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function 'void callback_handler(char*)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:36: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:51: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:59: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function 'void Java_com_nativeexample_JNIExampleInteace_callVoid(JNIEnv*, _jclass*)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:88: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function '_jobject* Java_com_nativeexample_JNIExamplnterface_getNewData(JNIEnv*, _jclass*, jint, _jstring*)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:103: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:110: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:117: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function '_jstring* Java_com_nativeexample_JNIExamplnterface_getStringInData(JNIEnv*, _jclass*, _jobject*)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:135: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:142: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function 'void initClassHelper(JNIEnv*, const char*,jobject**)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:163: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:170: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:177: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp: In function 'jint JNI_OnLoad(JavaVM*, void*)':  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:193: error: 'LOGI' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:195: error: 'LOGE' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:221: error: 'android' has not been declared  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:222: error: 'NELEM' was not declared in this scope  
D:/EclipseWorkspace/NativeExample/jni/JNIExampleInterface.cpp:223: error: 'LOGE' was not declared in this scope  
make: *** [/cygdrive/d/EclipseWorkspace/NativeExample/obj/local/armeabi/objs/JNIExampleInterface/JNIExampleInterface.o  
Error 1  
sh-4.1$   

我正在关注网络
http://android.wooyd.org/JNIExample/中的示例

如果我有什么错,请纠正我。如果我的问题不完美或无法理解,请发表评论并给我机会更正。

谢谢和问候,
SSuman185

4

2 回答 2

2

我只能通过使用以下声明来解决 LOGE 错误:

#define  LOG_TAG    "libJNIExInterface"  
#define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)  
#define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

“android_log .....”之前出现双倍分数。

另一个错误是“NELEM”在android运行时注册本机函数不是必需的,但只有当你有完整的android源代码时才能完成,当你编译这个应用程序和android源代码时,否则这不可能)。

因此,当您没有完整的 android 源代码时,Android 运行时注册是不可能的,无论如何我的应用程序在没有这个的情况下也可以正常工作。

于 2011-08-01T06:50:49.580 回答
1

如果有人仍然有这个问题:

日志记录宏已重命名,ALOGE现在就是这样。

于 2014-04-24T10:03:54.587 回答