I'm trying to cross-compile the open source library libsndfile with the Android NDK. My host is an Ubuntu subsystem under Windows 10 and the target an android system (for now anyone will do). For building, I use the autogen+configure setup as described in the doc of libsndfile. The compilation stops at the linking stage producing a lengthy logfile (a bit more than 400 lines) with several errors. The errors at the beginning seem to be non-critical but configure probing the compiler setup as described in this post. The last error message points towards a linker issue. Here what I think is the relevant excerpt of the log file:
#include "..." search starts here:
#include <...> search starts here:
/home/alan/android-ndk-r18/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/7.0.2/include
End of search list.
"/usr/bin/ld" --sysroot=../android-ndk-r18/platforms/android-17/arch-arm -z relro -X --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker -o a.out ../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib/crtbegin_dynamic.o -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib -L../android-ndk-r18/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib -L/home/alan/android-ndk-r18/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/7.0.2/lib/linux/arm -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib /tmp/conftest-5c2dd3.o -lgcc -ldl -lc -lgcc -ldl ../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib/crtend_android.o
/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:4138: $? = 1
configure:4176: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libsndfile"
| #define PACKAGE_TARNAME "libsndfile"
| #define PACKAGE_VERSION "1.0.29pre1"
| #define PACKAGE_STRING "libsndfile 1.0.29pre1"
| #define PACKAGE_BUGREPORT "[email protected]"
| #define PACKAGE_URL "http://www.mega-nerd.com/libsndfile/"
| #define PACKAGE "libsndfile"
| #define VERSION "1.0.29pre1"
| /* end confdefs.h. */
|
| int
| main ()
| {
|
| ;
| return 0;
| }
configure:4181: error: in `/home/alan/libsndfile':
configure:4183: error: C compiler cannot create executables
To make it even more precise, I think the problem is /usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
.
It seems people have already encountered this problem, as can be seen in this post,
but so far I haven't found a satisfying answer.
Following this suggestion on SO,
I tried to get more information about the error by running the linker on its own with the --verbose
option:
"/usr/bin/ld" --verbose --sysroot=../android-ndk-r18/platforms/android-17/arch-arm -z relro -X --enable-new-dtags --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /system/bin/linker -o a.out ../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib/crtbegin_dynamic.o -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib -L../android-ndk-r18/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib -L/home/alan/android-ndk-r18/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/7.0.2/lib/linux/arm -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib -L../android-ndk-r18/platforms/android-17/arch-arm/usr/lib /tmp/conftest-5c2dd3.o -lgcc -ldl -lc -lgcc -ldl ../android-ndk-r18/platforms/android-17/arch-arm/usr/lib/../lib/crtend_android.o
Unfortunately this had no effect on the output, which was the the same as in the logfile:
/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om i386pep i386pe
Does anyone have an Idea what I could try next?
The simplest solution is to just use a standalone toolchain so we take care of the details for you.
If you can't use that for some reason, the problem you're having is that you're invoking the compiler incorrectly.
If you're invoking it via the GCC wrapper (there is no GCC in r18; the GCC binaries are scripts that invoke Clang) then you're running in to https://github.com/android-ndk/ndk/issues/805.
If you're invoking Clang directly, you need to use -gcc-toolchain
to tell Clang where binutils is. i.e.
clang++ \
--target=armv7a-linux-androideabi17 \
-gcc-toolchain $NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
Note that if you're landing on this answer after NDK r19 has released, the answer is much simpler: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With