Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NDK for x86_64 has no reference for bcopy and index

I am trying to compile Lame sound library with Android NDK for x86_64 architecture. I am getting the below link error for undefined references to bcopy and index:

jni/libmp3lame/encoder.c:471: error: undefined reference to 'bcopy'
jni/libmp3lame/encoder.c:476: error: undefined reference to 'bcopy'
jni/libmp3lame/id3tag.c:1125: error: undefined reference to 'index'
jni/libmp3lame/newmdct.c:1036: error: undefined reference to 'bcopy'
jni/libmp3lame/util.c:685: error: undefined reference to 'bcopy'

The code successfully compiles for x86 and arm architectures.

So I digged through NDK's libs a bit and noticed that bcopy and index are both exported in libc.so for x86 and arm platforms but not for x86_64 (see below objdump outputs).

$> objdump -d android-ndk-r10d/platforms/android-21/arch-arm/usr/lib/libc.so | grep bcopy -A 6
0000b000 <bcopy>:
    b000:   e52db004 push   {fp}    ; (str fp, [sp, #-4]!)
    b004:   e28db000 add    fp, sp, #0
    b008:   e28bd000 add    sp, fp, #0
    b00c:   e8bd0800 ldmfd  sp!, {fp}
    b010:   e12fff1e bx lr


$> objdump -d android-ndk-r10d/platforms/android-21/arch-x86/usr/lib/libc.so | grep -A 6 bcopy
00009fb0 <bcopy>:
    9fb0:   55                   push   %ebp
    9fb1:   89 e5                   mov    %esp,%ebp
    9fb3:   5d                   pop    %ebp
    9fb4:   c3                   ret


$>  objdump -d android-ndk-r10d/platforms/android-21/arch-x86_64/usr/lib/libc.so | grep -A 6 bcopy
<<NOTHING FOUND>>

Any thoughts? Below are my Android.mk and Application.mk files.

Application.mk:

APP_ABI:=x86_64
APP_PLATFORM := android-21

Android.mk:

LOCAL_PATH := $(call my-dir)

APP_PLATFORM := android-21

include $(CLEAR_VARS)

LOCAL_MODULE        := libmp3lame

LOCAL_SRC_FILES     := \
...<list-of-.c-files>...

LOCAL_LDLIBS += -llog

include $(BUILD_SHARED_LIBRARY)
like image 526
Reza Avatar asked Jan 11 '15 23:01

Reza


1 Answers

You can fix this cleanly with a single line in Application.mk (docs):

APP_CFLAGS += -DSTDC_HEADERS

Why?

LAME assumes that certain symbols will be accessible without explicit inclusion via #include. However, it also provides a way to signal that explicit inclusion is necessary.

In my distribution, the conflictive files (machine.h and id3tag.c) have something like this:

#ifdef STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif

This is the block you need to trigger, by setting the STDC_HEADERS preprocessor variable. The line above, with the -D flag, tells the C compiler to create it.

like image 99
slezica Avatar answered Sep 20 '22 12:09

slezica