1

I have tried to build an Android subsystem (external/tinyalsa). I got an error (error: undefined reference to '__android_log_print') while building the system.

I use cm-14.1 to build android-7.1.2_r2 system, and I inserted ALOGx functions in external/tinyalsa/pcm.c for debugging purpose. Below is the Android.mk file I tried to build.

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)

The problem is, when I didn't try to build tinyplay, tinymixer, and tinycap. The build fails with following errors.

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'

I added #define LOG_TAG and header file #include <cutils/log.h>,#include <android.log.h>, but it doesn't be built.

(NOTE) the libtinyalsa is successfully built (even it uses a bunch of ALOGx functions!.

Any idea?

Thanks in advance.

Joonsung Kim
  • 246
  • 1
  • 3
  • 15

1 Answers1

0

The error occurs due to there's no definition of __android_log_print in host(x86) system (more especially, in liblog)

Below is the failure log

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)

As you can see, the error occurs when trying to build tinyplay for host (x86) system.

If you comment out multiple lines for building tinplay for the host system, you can successfully build without any errors (Check the following code snippets).

#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

(NOTE) It is still weird that the tinyplay for x86 system doesn't be built correctly because liblog is built for host (x86 linux) system as both static and shared libraries.

Anyway, you can simply build the tinyplay by omitting compilation for x86 system.

Joonsung Kim
  • 246
  • 1
  • 3
  • 15