<AOSP> undefined reference to '__android_log_print' 构建 Android 系统时出错

<AOSP> undefined reference to '__android_log_print' error while building an Android system

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

我使用cm-14.1构建android-7.1.2_r2系统,为了调试目的,我在external/tinyalsa/pcm.c中插入了ALOGx函数。 下面是我尝试构建的 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 函数!

有什么想法吗?

提前致谢。

由于在主机(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

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

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