Skip to content

Problem compiling for Android #2904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lemberh opened this issue Oct 16, 2020 · 9 comments
Closed

Problem compiling for Android #2904

lemberh opened this issue Oct 16, 2020 · 9 comments

Comments

@lemberh
Copy link
Contributor

lemberh commented Oct 16, 2020

I have followed this tutorial from wiki.
I used sources from the latest release https://github.com/xianyi/OpenBLAS/releases/tag/v0.3.10

This is my build script after the path adjustment

# Set path to ndk-bundle
export NDK_BUNDLE_DIR=/Users/rnaz/Library/Android/sdk/ndk/21.3.6528147
# Export PATH to contain directories of clang and aarch64-linux-android-* utilities
export PATH=${NDK_BUNDLE_DIR}/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/:${NDK_BUNDLE_DIR}/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH
# Setup LDFLAGS so that loader can find libgcc and pass -lm for sqrt
export LDFLAGS="-L${NDK_BUNDLE_DIR}/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x -lm"
# Setup the clang cross compile options
export CLANG_FLAGS="-target aarch64-linux-android --sysroot ${NDK_BUNDLE_DIR}/platforms/android-23/arch-arm64 -gcc-toolchain ${NDK_BUNDLE_DIR}/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/"
# Compile
make TARGET=ARMV8 ONLY_CBLAS=1 AR=ar CC="clang ${CLANG_FLAGS}" HOSTCC=gcc -j4

Compilation ended with an error:

clang: warning: argument unused during compilation: '-install_name /Users/rnaz/StudioProjects/OpenBLAS/exports/../libopenblas.0.dylib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-dynamiclib' [-Wunused-command-line-argument]
/Users/rnaz/Library/Android/sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ld:osx.def: file format not recognized; treating as linker script
/Users/rnaz/Library/Android/sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ld:osx.def:2: syntax error
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libopenblas_haswellp-r0.3.10.dylib] Error 1
make: *** [shared] Error 2

Also if I just compile with make compilation succeed
Can anybody suggest what might be wrong

@martin-frbg
Copy link
Collaborator

Can you post the contents (or first few lines) of the osx.def the linker does not like ?

@lemberh
Copy link
Contributor Author

lemberh commented Oct 16, 2020

This is actually executable file
here is the result of head -5 /Users/rnaz/Library/Android/sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ld

�����@� H__PAGEZEROx__TEXT��__text__TEXT���__stubs__TEXT
��
�__stub_helper__TEXT��>���__cstring__TEXT���
��__const__TEXT�����__unwind_info__TEXT�(%�__eh_frame__TEXT����__DATA���__program_vars__DATA�(�__got__DATA(�X(�k__nl_symbol_ptr__DATA����v__la_symbol_ptr__DATA��X��x__const__DATA�(��__data__DATA@�PJ@�__common__DATA��__bss__DATA��k~H__LINKEDITp D��D�"�0�� ���h��0p u�z
PsXw �
/usr/lib/dyld�s�Y:���ۂb&$

I have 3 versions of ndk and on all of them is the same problem, also it is reproducible for ARMV7 build
Versions of NDK:
21.0.6113669
21.2.6472646
21.3.6528147

And also I'm using Mac-OS

@martin-frbg
Copy link
Collaborator

martin-frbg commented Oct 17, 2020

Hm, that file is supposed to be the list of symbols (functions) exported by the shared library. I need to check how it is supposed to look for osx, maybe what you are seeing is native osx or ios format and nobody tried to cross-compile for Android on OSX recently

@martin-frbg
Copy link
Collaborator

BTW, as you wrote that just compiling with make succeeded (that is, without passing the CLANG_CFLAGS to clang, I assume ?),
did it result in a usable library for Android ?

@brada4
Copy link
Contributor

brada4 commented Oct 17, 2020

Add parameter FC=none because native fortran compiler makes native OSX fortran objects that android/linux clang will not link anywhere.

@lemberh
Copy link
Contributor Author

lemberh commented Oct 19, 2020

Thanks for the help guys!
My first problem was because I didn't do make clean after compiling with just make it would be the version for OSX
But after that, I was still getting errors like this:

clang -target arm-linux-androideabi -marm -mfpu=vfp -mfloat-abi=softfp --sysroot /Users/rnaz/Library/Android/sdk/ndk/21.3.6528147/platforms/android-23/arch-arm -gcc-toolchain /Users/rnaz/Library/Android/sdk/ndk/21.3.6528147toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin -O2 -DMAX_STACK_ALLOC=2048 -marm -mfloat-abi=softfp -Wall -DF_INTERFACE_GFORT -fPIC -DNO_LAPACK -DNO_LAPACKE -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=8 -DMAX_PARALLEL_NUMBER=1 -DVERSION="0.3.10" -mfpu=neon -march=armv7-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=cblas_dsdot -DASMFNAME=cblas_dsdot_ -DNAME=cblas_dsdot_ -DCNAME=cblas_dsdot -DCHAR_NAME="cblas_dsdot_" -DCHAR_CNAME="cblas_dsdot" -DNO_AFFINITY -I.. -I. -UDOUBLE -UCOMPLEX -DCBLAS -c dsdot.c -o cblas_dsdot.o
imax.c:39:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~

Finally, I have managed to compile the project with help from this comment #2005 (comment)
I think documentation from the Wiki doesn't work because of those changes in NDK19 https://developer.android.com/ndk/guides/other_build_systems#overview

This is my working script

export NDK=/Users/rnaz/Library/Android/sdk/ndk/21.3.6528147
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/darwin-x86_64
make \
    TARGET=ARMV7 \
    ONLY_CBLAS=1 \
    CC="$TOOLCHAIN"/bin/armv7a-linux-androideabi21-clang \
    AR="$TOOLCHAIN"/bin/arm-linux-androideabi-ar \
    HOSTCC=gcc \
    ARM_SOFTFP_ABI=1 \
    -j4

@brada4
Copy link
Contributor

brada4 commented Oct 20, 2020

Add a paragraph with your NDK version and the command line to wiki, it is open to all github

@martin-frbg
Copy link
Collaborator

Thank you very much for updating the wiki - in particular the added script for X86 should solve #2768

@lemberh
Copy link
Contributor Author

lemberh commented Oct 21, 2020

No problem. And thank you guys for maintaining this library it helped me a lot in my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants