C/C ++ development: How to output Log information in NDK and source code!
NDK:
1. include header files
# Include
2. Android. mk contains libraries.
LOCAL_LDLIBS + =-L $ (SYSROOT)/usr/lib-llog
The above is required, otherwise error: undefined reference to '_ android_log_print' will appear'
LOCAL_SHARED_LIBRARIES: = libdl \
Liblog \ # tested that NDK compilation in Eclipse is dispensable and useless! But it must be him in the source code, so add them all!
Libpre_AppUpgrade \
Libpre_AppArea \
3. Define in your jni File
# Define LOGD (...) _ android_log_print (ANDROID_LOG_DEBUG, LOG_TAG, __va_args _) // define the LOGD type
# Define LOGI (...) _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, __va_args _) // define the LOGI type
# Define LOGW (...) _ android_log_print (ANDROID_LOG_WARN, LOG_TAG, __va_args _) // define the LOGW type
# Define LOGE (...) _ android_log_print (ANDROID_LOG_ERROR, LOG_TAG, __va_args _) // define the LOGE type
# Define LOGF (...) _ android_log_print (ANDROID_LOG_FATAL, LOG_TAG, __va_args _) // define the LOGF type
The source code of adnroid4.2 has added a header for all LOGD and so on,
# Define ALOGD (...) _ android_log_print (ANDROID_LOG_DEBUG, LOG_TAG, __va_args _) // define the LOGD type
# Define ALOGI (...) _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, __va_args _) // define the LOGI type
# Define ALOGW (...) _ android_log_print (ANDROID_LOG_WARN, LOG_TAG, __va_args _) // define the LOGW type
# Define ALOGE (...) _ android_log_print (ANDROID_LOG_ERROR, LOG_TAG, __va_args _) // define the LOGE type
# Define ALOGF (...) _ android_log_print (ANDROID_LOG_FATAL, LOG_TAG, __va_args _) // define the LOGF type
Note that if you do not want to define the above Macros in every jni file, the speculative method can be defined in: D: \ android-ndk-r9d \ platforms \ android-19 \ arch-arm \ usr \ include \ android \ log. h in progress! Of course, this compilation can only be used on your local machine ~
Source code development:
1. Android. mk contains libraries.
LOCAL_LDLIBS + =-L $ (SYSROOT)/usr/lib-llog
LOCAL_SHARED_LIBRARIES: = libdl \
Liblog \ // must be added to the source code
Libpre_AppUpgrade \
Libpre_AppArea \
2. include header files # include
3. Remember to include the library header file when using it.