3

we created static library with hugin application on armeabi-v7a and we tried to connect it with our shared library in Android using Cmakelist. We can see the library and his header without any problem, but when I am trying compile that, it failed with this error:

Build command failed.

Error while executing process

....\cmake\3.6.3155560\bin\cmake.exe with arguments {--build ....\OpenCVExample-master\app.externalNativeBuild\cmake\debug\arm64-v8a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o

[2/2] Linking CXX shared library ........\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so FAILED: cmd.exe /C "cd . && ....\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android --gcc-toolchain=../../ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=../../ndk-bundle/platforms/android-21/arch-arm64 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=gnu++11 -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ........\build\intermediates\cmake\debug\obj\arm64-v8a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o ../../../../src/main/jniLibs/arm64-v8a/libhugin.a ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so -lm "....\ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" && cd ."

../../../../src/main/jniLibs/arm64-v8a/libhugin.a: error adding symbols: File in wrong format

clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

ninja: build stopped: subcommand failed.

We know that our device uses arm64-v8a ABI, but we have serious problems to compile our static library to this architecture, so we use armeabi-v7a. According this post below, it should be compatibile.

Is arm64-v8a compatible with armeabi-v7a?

Do you have any idea what could be wrong with our static library or project?? Thank you very much

smeidak
  • 285
  • 1
  • 3
  • 13
  • 1
    Saying that an arm64-v8a capable device can run armeabi-v7a code doesn't mean that a single application can use both types of code. – Michael Burr Aug 16 '17 at 07:31

2 Answers2

0

The armeabi-v7a apk would run on arm64 platform; but to compile into arm64 apk, needs arm64 lib to compile into arm64 app ( apk )

Gerry
  • 1,223
  • 9
  • 17
0

I had a similar issue with clang for aarch64 in my case static library was compiled with enabled lto - I had below line in my cmake

target_compile_options(addrlib PRIVATE -flto=thin)

I would suggest to you confirm that LTO is disabled for a static library

Also, you probably would like to confirm that a static library src/main/jniLibs/arm64-v8a/libhugin.a target arch is the same as your shared library arch You could try bellow approach

# from src/main/jniLibs/arm64-v8a/
mdkir test
cd test
ar -x ../libhugin.a
# you would get some amount of object files from the static lib
file <object file name>.o
<object file name>.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped

Also, see here How to see the compilation platform of a static library file

N0dGrand87
  • 727
  • 1
  • 9
  • 16