ARM-software / ComputeLibrary

The Compute Library is a set of computer vision and machine learning functions optimised for both Arm CPUs and GPUs using SIMD technologies.
MIT License
2.82k stars 774 forks source link

Build Error for Android Compute Library on M1-Based macOS #1008

Closed GGGGxxxxxxxxr closed 1 year ago

GGGGxxxxxxxxr commented 1 year ago

Hi, I am trying to build ACL for android and I previously used Linux_x86 system for building, and it worked fine. When I switched to my M1Pro-based MacBook, I followed every same step as I did previously with Linux, but I encountered the building error:

llvm-ar rc build/libarm_compute_core-static.a aarch64-linux-android-clang -o build/libarm_compute_core.dylib -ldl -Wl,--no-undefined -dynamiclib -Lbuild -L. -ldl llvm-ranlib build/libarm_compute_core-static.a clang-14: warning: argument unused during compilation: '-dynamiclib' [-Wunused-command-line-argument]

aarch64-linux-android-clang++ -o build/src/graph/DataLayerVisitor.o -c -DARCH_ARM -Wextra -Wdisabled-optimization -Wformat=2 -Winit-self -Wstrict-overflow=2 -Wswitch-default -Woverloaded-virtual -Wformat-security -Wctor-dtor-privacy -Wsign-promo -Weffc++ -Wno-overlength-strings -Wall -std=c++14 -pedantic -Wno-vla-extension -march=armv8-a -DENABLE_FP16_KERNELS -DENABLE_FP32_KERNELS -DENABLE_QASYMM8_KERNELS -DENABLE_QASYMM8_SIGNED_KERNELS -DENABLE_QSYMM16_KERNELS -DENABLE_INTEGER_KERNELS -DENABLE_NHWC_KERNELS -DENABLE_NCHW_KERNELS -O3 -fstack-protector-strong -Wno-redundant-move -Wno-pessimizing-move -D_GLIBCXX_USE_NANOSLEEP -DARM_COMPUTE_CPP_SCHEDULER=1 -DENABLE_NEON -DARM_COMPUTE_ENABLE_NEON -DARM_COMPUTE_GRAPH_ENABLED -DANDROID -DARM_COMPUTE_CPU_ENABLED -DARM_COMPUTE_ASSERTS_ENABLED -DARM_COMPUTE_VERSION_MAJOR=28 -DARM_COMPUTE_VERSION_MINOR=0 -DARM_COMPUTE_VERSION_PATCH=0 -Iinclude -I. -Ibuild/build/src/core -Ibuild/src/core -Ibuild/src/core/NEON/kernels/convolution/common -Isrc/core/NEON/kernels/convolution/common -Ibuild/src/core/NEON/kernels/convolution/winograd -Isrc/core/NEON/kernels/convolution/winograd -Ibuild/src/core/NEON/kernels/arm_conv/depthwise -Isrc/core/NEON/kernels/arm_conv/depthwise -Ibuild/src/core/NEON/kernels/arm_conv/pooling -Isrc/core/NEON/kernels/arm_conv/pooling -Ibuild/src/core/NEON/kernels/arm_conv -Isrc/core/NEON/kernels/arm_conv -Ibuild/src/core/NEON/kernels/assembly -Isrc/core/NEON/kernels/assembly -Ibuild/arm_compute/core/NEON/kernels/assembly -Iarm_compute/core/NEON/kernels/assembly -Ibuild/src/cpu/kernels/assembly -Isrc/cpu/kernels/assembly src/graph/DataLayerVisitor.cpp aarch64-linux-android-clang++ -o build/src/graph/Graph.o -c -DARCH_ARM -Wextra -Wdisabled-optimization -Wformat=2 -Winit-self -Wstrict-overflow=2 -Wswitch-default -Woverloaded-virtual -Wformat-security -Wctor-dtor-privacy -Wsign-promo -Weffc++ -Wno-overlength-strings -Wall -std=c++14 -pedantic -Wno-vla-extension -march=armv8-a -DENABLE_FP16_KERNELS -DENABLE_FP32_KERNELS -DENABLE_QASYMM8_KERNELS -DENABLE_QASYMM8_SIGNED_KERNELS -DENABLE_QSYMM16_KERNELS -DENABLE_INTEGER_KERNELS -DENABLE_NHWC_KERNELS -DENABLE_NCHW_KERNELS -O3 -fstack-protector-strong -Wno-redundant-move -Wno-pessimizing-move -D_GLIBCXX_USE_NANOSLEEP -DARM_COMPUTE_CPP_SCHEDULER=1 -DENABLE_NEON -DARM_COMPUTE_ENABLE_NEON -DARM_COMPUTE_GRAPH_ENABLED -DANDROID -DARM_COMPUTE_CPU_ENABLED -DARM_COMPUTE_ASSERTS_ENABLED -DARM_COMPUTE_VERSION_MAJOR=28 -DARM_COMPUTE_VERSION_MINOR=0 -DARM_COMPUTE_VERSION_PATCH=0 -Iinclude -I. -Ibuild/build/src/core -Ibuild/src/core -Ibuild/src/core/NEON/kernels/convolution/common -Isrc/core/NEON/kernels/convolution/common -Ibuild/src/core/NEON/kernels/convolution/winograd -Isrc/core/NEON/kernels/convolution/winograd -Ibuild/src/core/NEON/kernels/arm_conv/depthwise -Isrc/core/NEON/kernels/arm_conv/depthwise -Ibuild/src/core/NEON/kernels/arm_conv/pooling -Isrc/core/NEON/kernels/arm_conv/pooling -Ibuild/src/core/NEON/kernels/arm_conv -Isrc/core/NEON/kernels/arm_conv -Ibuild/src/core/NEON/kernels/assembly -Isrc/core/NEON/kernels/assembly -Ibuild/arm_compute/core/NEON/kernels/assembly -Iarm_compute/core/NEON/kernels/assembly -Ibuild/src/cpu/kernels/assembly -Isrc/cpu/kernels/assembly src/graph/Graph.cpp

ld: error: undefined symbol: main

referenced by crtbegin.c /Users/leilu/library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/32/crtbegin_dynamic.o:(_start_main) referenced by crtbegin.c /Users/leilu/library/Android/sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/32/crtbegin_dynamic.o:(_start_main) clang-14: error: linker command failed with exit code 1 (use -v to see invocation) scons: *** [build/libarm_compute_core.dylib] Error 1 scons: building terminated because of errors.

I assume the shared library shall be in the format of .so file, while in macOS, it came to .dylib.

Platform: Building for Android

Operating System: macOS, M1 chip;

I tried several versions of ndk, from Version 20 to 24, but seems like nothing helps.

The command I used: scons Werror=0 -j8 debug=0 asserts=1 neon=1 opencl=0 os=android arch=arm64-v8a

( as I did some modifications on the src code, so i set Werror as 0 due to some warnings on unused variables)

Thanks for the patience!

morgolock commented 1 year ago

Hi @GGGGxxxxxxxxr

Cross-compilation of the library to target Android is only supported on Linux hosts.

I reproduced the issue, scons seems to get confused and emit commands as if the target was macos instead of android

Hope this helps.

GGGGxxxxxxxxr commented 1 year ago

Thanks! But on MacOS Host, i have commented the shared-library parts in Sconscript, and only build static library only. It worked on my macbook actually... I would go back to Linux machine but just noted that building static library only could work on macos hosts. Thanks again!