您的位置:首页 > 移动开发 > Android开发

android ndk添加打印 解决undefined reference to __android_log_print'问题

2014-02-21 19:45 525 查看
在so库中添加打印,android虚拟机不能打印的问题,网上答案太多,一个个试出来的,先记录下来

用的是android-ndk-r8c 

遇到的一个问题 用了stdio.h中的printf()添加打印后,在虚拟机中打印不能输出

需要引用库,添加 几个地方才能打开打印

#include <android/log.h>

定义宏
#define LOG_TAG "communicate"

#define LOGI(args...) \
__android_log_print(ANDROID_LOG_INFO,LOG_TAG, args)

#define DEBUG(args...) \
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, args)

#define ERROR(args...) \
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, args)

#else

#define LOGI(args...)
#define DEBUG(args...)
#define ERROR(args...)

#endif


ndk-build编译

发现这个修改之后会出现undefined reference to __android_log_print'  这个问题

然后继续修改Android.mk文件

需要加上几句话

LOCAL_LDLIBS := -lm -llog

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog

LOCAL_SHARED_LIBRARIES :=\
liblog.so\
libutils \

搞定 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息