記一次JNI log導入失敗問題

在作本身項目的時候,因爲須要在JNI使用log的功能,定義代碼以下:android

#ifndef ALOHA_JNI_LOG_H

#define ALOHA_JNI_LOG_H
#include "jni.h"
#include "android/log.h"
#include <cstdlib>


#ifndef JNI_LOG
#define JNI_LOG "jni_log"
#endif
//build log
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, JNI_LOG, __VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, JNI_LOG, __VA_ARGS__)
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, JNI_LOG, __VA_ARGS__)
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, JNI_LOG, __VA_ARGS__)
#endif //ALOHA_JNI_LOG_H

而後在一個c++文件中導入頭文件:c++

#include "../jni_log.h"

結果報錯了,錯誤信息以下:網站

"undefined reference to `__android_log_write".

一看是說log文件沒有導入成功,在網站上查了挺久都是那麼兩種方法,後來在overflow裏面查到了解決辦法,須要單獨連接對應的庫:ui

target_link_libraries(hello-jni
                        android
                      speech_vad
                       ${log-lib} )
#這裏要單獨連接一下,我也不知道爲啥,若是有大神知道,麻煩指點一下
target_link_libraries( speech_vad
                       ${log-lib} )

對應解決方案地址:google

https://stackoverflow.com/questions/40844163/android-ndkcmake-undefined-reference-to-android-log-write-when-using-log?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qacode

相關文章
相關標籤/搜索