[Android 9.0] the usbhost module in the system/core cannot output log to logcat

Phenomenon: the native Android 9.0 SDK, system / core / libushost is the module used by usb module to communicate with the driver. When debugging, you want to output log to logcat, turn on the debugging switch to recompile the code, and report the error of "undefined reference to '"

FAILED: out/soong/.intermediates/system/core/libusbhost/libusbhost/linux_glibc_x86_64_shared/libusbhost.so 
prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++  @out/soong/.intermediates/system/core/libusbhost/libusbhost/linux_glibc_x86_64_shared/libusbhost.so.rsp out/soong/.intermediates/external/compiler-rt/libcompiler_rt-extras/linux_glibc_x86_64_static/libcompiler_rt-extras.a out/soong/.intermediates/external/libcxx/libc++/linux_glibc_x86_64_shared/libc++.so  -o out/soong/.intermediates/system/core/libusbhost/libusbhost/linux_glibc_x86_64_shared/libusbhost.so -shared -Wl,-soname,libusbhost.so -target x86_64-linux-gnu -Bprebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin  -Wl,--no-undefined -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 -m64 -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 -ldl -lpthread -lm -lrt -Wl,-rpath,\$ORIGIN/../lib64 -Wl,-rpath,\$ORIGIN/lib64  -nodefaultlibs -lgcc_s -lgcc -lc -lgcc_s -lgcc
system/core/libusbhost/usbhost.c:211: error: undefined reference to '__android_log_print'
system/core/libusbhost/usbhost.c:278: error: undefined reference to '__android_log_print'
system/core/libusbhost/usbhost.c:301: error: undefined reference to '__android_log_print'
system/core/libusbhost/usbhost.c:305: error: undefined reference to '__android_log_print'
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
[ 16% 97/605] Construct recovery from boot
ninja: build stopped: subcommand failed.
11:04:39 ninja failed with: exit status 1

Cause of the problem:

The root cause of this problem is that the compiler cannot find the corresponding function implementation body at the time of linking, which is independent of the missing header file, that is, the liblog library where the function implementation body is located cannot be found

Solution: modify Android.bp and put the liblog shared library declaration outside the target. It's not clear why the target can't be linked

diff --git a/libusbhost/Android.bp b/libusbhost/Android.bp
old mode 100644
new mode 100755
index fc6f305..43076eb
--- a/libusbhost/Android.bp
+++ b/libusbhost/Android.bp
@@ -24,13 +24,16 @@ cc_library {
     srcs: ["usbhost.c"],
     cflags: ["-Werror"],
     export_include_dirs: ["include"],
+    shared_libs: [
+       "liblog",
+    ],
     target: {
         android: {
             cflags: [
                 "-g",
                 "-DUSE_LIBLOG",
             ],
-            shared_libs: ["liblog"],
+            //shared_libs: ["liblog"],
         },
         darwin: {
             enabled: false,

Keywords: Mobile Linux Android SDK Linker

Added by shahansudu on Sun, 10 Nov 2019 18:36:01 +0200