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:
Answer from Shlublu on Stack OverflowIf 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
[...]
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 -nodefaultlibs or -nostdlibs.
Here a quote from GCC documentation (clang interface is just the same):
One of the standard libraries bypassed by
-nostdliband-nodefaultlibsislibgcc.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.
In some Makefiles it tries to find the search path for libgcc by executing:
$(CC) -print-libgcc-file-name
This fails if no sysroot is defined, so add sysroot manually. Have a look at the config.mk where it says:
CC := $(CROSS_COMPILE)gcc
Change it to:
ifdef PKG_CONFIG_SYSROOT_DIR
CC = $(CROSS_COMPILE)gcc --sysroot=$(PKG_CONFIG_SYSROOT_DIR)
else
CC = $(CROSS_COMPILE)gcc
endif
change cross_compile to another directory, for 4.1.15
source /<dir>/environment-setup-cortexa9hf-neon-poky-linux-gnueabi