int main(int argc, char **argv)
{
return 0;
}
I cross compile (host= linux x86_64, target= linux aarch64)
/path/to/clang --target=aar
Just in case I use Qt and for running apps on Android with Qt versions greater than 5.11, had this problem with the latest Android Sdk and NDK-r20c. and after some struggles, finally it worked with NDK-r19c.
Clang does not come with a linker, it relies on ld
instead. And ld
depends on libgcc.a
and/or libgcc.so
on your system (regardless this is the LLVM linker ld.lld
or GNU ld). This is the reason why you have this error message.
So the answer is actually:
(a) the linker requires libgcc to do its own linking work
A lot more details on this are available here at omniprog.info:
If we want to get rid of GCC and use clang as our default compiler on the system, we may have to make some adjustments on some RPM-based systems. Clang does not provide a linker, but relies on the system's linker, typically ld, to link executables. This is the case even on FreeBSD and Mac OS X systems where Clang is the default compiler. We can see this using the -v option to clang++. Now, ld won't work without the following files:
libgcc.a
libgcc_s.so
[...]
You must compile with the option -nodefaultlib
or -nostdlibs
.
Here a quote from GCC documentation (clang interface is just the same):
One of the standard libraries bypassed by
-nostdlib
and-nodefaultlibs
islibgcc.a
, a library of internal subroutines which GCC uses to overcome shortcomings of particular machines, or special needs for some languages.
You may have to execute c++ static initialization routines and/or use what is provided by the object files crt<x>.o
in the lib directory. These files are part of libc
and provides executable entry point.