Wednesday, February 7, 2024

[SOLVED] Forcing Clang to use GCC C++ runtime libraries

Issue

I'd like to use Clang as a cross-compiler (which it inherently is, according to https://clang.llvm.org/docs/CrossCompilation.html). The quirk of my setup is that I run it on Windows (MSYS2 installation) to build the code for Linux AArch64 board. It fails on the link stage:

ld.lld: error: cannot open C:/msys64/clang64/lib/clang/17/lib/linux/libclang_rt.builtins-aarch64.a: No such file or directory
[cmake]     ld.lld: error: unable to find library -lunwind

The package for Clang in MSYS2 doesn't provide that file. But if I understand correctly, it's a part of C++ runtime libraries, which I could try to replace with GCC C++ runtime libraries. I think I should have these because I have GCC installed on that board and I have downloaded the sysroot from there to my development machine.

How can I change the C++ runtime libs used by Clang during build?


Solution

I believe you need -rtlib=libgcc -unwindlib=libgcc.

And if you wanted to do the opposite, that would be -rtlib=compiler-rt -unwindlib=libunwind (those seem to be your defaults).

You might also want -stdlib=libstdc++ (instead of -stdlib=libc++), and I'm assuming you already added --target=... and --sysroot=....



Answered By - HolyBlackCat
Answer Checked By - Pedro (WPSolving Volunteer)