flame / blis

BLAS-like Library Instantiation Software Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to cross-compile libraries for use on Android?

leo4678 opened this issue · comments

when complie blis using Android NDK 23, error is ld : error: unable to find library -lrt

./configure --enable-threading=pthreads CC=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang CXX=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++  AR=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar RANLIB=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ranlib LIBPTHREAD=$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/lib64/libc++.so arm64

make -j32
Dynamically linking lib/arm64/libblis.so
Archiving lib/arm64/libblis.a
ld: error: unable to find library -lrt
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
Makefile:790: recipe for target 'lib/arm64/libblis.so' failed
make: *** [lib/arm64/libblis.so] Error 1

libpthread and librt libraries were included in libc
https://developer.android.com/ndk/guides/stable_apis#c_library

How to quickly integrate blis on Android?

"Librt and Libpthread are included in Bionic lib, which substitutes GLibC in Android, so just remove -pthread (or -lpthread -lrt) flags from your Makefiles" (ref)

@leekillough is there an easy way to check for Bionic in configure?

@devinamatthews SO to the rescue

You can see an example in configure of testing preprocessor macros, for example, here.

@devinamatthews and I talked about formally supporting this. I'm thinking maybe a --enable-android option?

Actually, I can't seem to convince myself that -lpthread is ever needed on line 913 since pthreads is included in the link command by default (via line 579). 🤔

I prefer the autodetection option: #ifdef __BIONIC__. A separate explicit option to force it is fine, but the default autodetection should detect Bionic.

It shouldn't be too hard. RISC-V already autodetects using preprocessor macros.

@leekillough Just to clarify, you're referring to trying to build a dummy .c file that contains #ifdef __BIONIC__ and branching within configure based on the result of that compilation attempt?

I am saying that, just like in RISC-V, it is possible to detect properties in the build environment with preprocessor macros.

A .h or similar file can be "preprocessed" and produce an output based on macros, which can then be parsed or grep'ed for a certain output.

Bionic seems to be an easy property to detect through preprocessor macros.

With cc -E or similar, a source file dependent on Bionic macros can be tested. The source file would have things like #ifdef __BIONIC_ in it, and would output source code dependent on the presence of the macro (whether defined or not).

It is possible to parse the preprocessor output without having to fully compile the source. Please see the RISC-V autodetection code as an example.

See the RISC-V autodetection code for examples

Thanks for clarifying, @leekillough. Could you share a link to the RISC-V autodetection code?

blis/configure

Line 1252 in a0b04e3

# Special case for RISC-V, whose architecture can be detected with

I'm willing to write a PR for this issue this evening.