Why does clang still need libgcc.a to compile my code?

前端 未结 3 1985
情书的邮戳
情书的邮戳 2021-02-07 12:21
int main(int argc, char **argv)
{
    return 0;
}

I cross compile (host= linux x86_64, target= linux aarch64)

/path/to/clang --target=aar

3条回答
  •  猫巷女王i
    2021-02-07 12:46

    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
    [...]

提交回复
热议问题