<aosp>未定义对&#39; __ android_log_print&#39;的引用构建Android系统时出错

时间:2018-01-31 23:19:23

标签: android android-source

我尝试构建一个Android子系统(external/tinyalsa)。构建系统时出现错误(error: undefined reference to '__android_log_print')。

我使用cm-14.1构建android-7.1.2_r2系统,并在ALOGx中插入external/tinyalsa/pcm.c个函数以进行调试。 以下是我尝试构建的 Android.mk 文件。

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

ifeq ($(TARGET_TINY_ALSA_IGNORE_SILENCE_SIZE),true)
   LOCAL_CFLAGS += -DIGNORE_SILENCE_SIZE
endif

LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= mixer.c pcm.c
LOCAL_MODULE := libtinyalsa
LOCAL_SHARED_LIBRARIES:= liblog libcutils libutils
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_SHARED_LIBRARY)

ifeq ($(HOST_OS), linux)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= mixer.c pcm.c
LOCAL_MODULE := libtinyalsa
LOCAL_STATIC_LIBRARIES:= liblog libcutils libutils
LOCAL_CFLAGS += -Werror

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_HOST_STATIC_LIBRARY)
endif

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= tinyplay.c
LOCAL_MODULE := tinyplay
LOCAL_SHARED_LIBRARIES:= liblog libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror -Wno-missing-field-initializers

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_EXECUTABLE)

ifeq ($(HOST_OS), linux)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= tinyplay.c
LOCAL_MODULE := tinyplay
LOCAL_STATIC_LIBRARIES:= liblog libcutils libutils liblog libtinyalsa
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror -Wno-missing-field-initializers

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_HOST_EXECUTABLE)
endif

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= tinycap.c
LOCAL_MODULE := tinycap
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror -Wno-missing-field-initializers

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= tinymix.c
LOCAL_MODULE := tinymix
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES:= external/tinyalsa/include
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
LOCAL_SRC_FILES:= tinypcminfo.c
LOCAL_MODULE := tinypcminfo
LOCAL_SHARED_LIBRARIES:= libcutils libutils libtinyalsa
LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -Werror

LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

include $(BUILD_EXECUTABLE)

问题是,当我没有尝试构建tinyplaytinymixertinycap时。构建失败并出现以下错误。

external/tinyalsa/pcm.c:863: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:870: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:879: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:884: error: undefined reference to '__android_log_print'

我添加了#define LOG_TAG和标题文件#include <cutils/log.h>#include <android.log.h>,但它没有被构建。

(注意) libtinyalsa已成功构建(即使它使用了一堆ALOGx函数!。

有什么想法吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

由于主机(x86)系统中没有__android_log_print的定义(更具体地说,在liblog中)

,因此发生错误

以下是失败日志

host Executable: tinyplay (/work/backup/drim/android_drim/out/host/linux-x86/obj/EXECUTABLES/tinyplay_intermediates/tinyplay)
FAILED: /bin/bash -c "prebuilts/misc/linux-x86/ccache/ccache prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++             /work/backup/drim/android_drim/out/host/linux-x86/obj/EXECUTABLES/tinyplay_intermediates/tinyplay.o        -Wl,--whole-archive   -Wl,--no-whole-archive   /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/liblog_intermediates/liblog.a /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/libutils.a /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/liblog_intermediates/liblog.a /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/libtinyalsa_intermediates/libtinyalsa.a /work/backup/drim/android_drim/out/host/linux-x86/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a    -lc++  -Wl,-rpath-link=/work/backup/drim/android_drim/out/host/linux-x86/obj/lib -Wl,-rpath,\\\$ORIGIN/../lib64 -Wl,-rpath,\\\$ORIGIN/lib64  -L/work/backup/drim/android_drim/out/host/linux-x86/obj/lib    -m64 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined-version    --gcc-toolchain=prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8 --sysroot prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/sysroot -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/lib/gcc/x86_64-linux/4.8 -Lprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/lib64/ -target x86_64-linux-gnu    -pie -nodefaultlibs -o /work/backup/drim/android_drim/out/host/linux-x86/obj/EXECUTABLES/tinyplay_intermediates/tinyplay   -lpthread -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc"
external/tinyalsa/pcm.c:863: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:870: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:879: error: undefined reference to '__android_log_print'
external/tinyalsa/pcm.c:884: error: undefined reference to '__android_log_print'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

如您所见,尝试为主机(x86)系统构建tinyplay时会发生错误。

如果您为主机系统注释多行以构建tinplay,则可以成功构建而不会出现任何错误(请查看以下代码段)。

#ifeq ($(HOST_OS), linux)
#include $(CLEAR_VARS)
#LOCAL_C_INCLUDES:= external/tinyalsa/include
#LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
#LOCAL_SRC_FILES:= tinyplay.c
#LOCAL_MODULE := tinyplay
#LOCAL_STATIC_LIBRARIES:= liblog libcutils libutils liblog libtinyalsa
#LOCAL_MODULE_TAGS := optional
#LOCAL_CFLAGS += -Werror -Wno-missing-field-initializers

#LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr

#include $(BUILD_HOST_EXECUTABLE)
#endif

(注意)由于tinyplay是为主机(x86 linux)系统构建的,因此x86系统的liblog无法正确构建仍然很奇怪静态和共享库。

无论如何,你可以通过省略x86系统的编译来简单地构建tinyplay