Hi!
I have been using --gcc_toolchain
with clang successfully to build my C++ application using a custom GCC toolchain:
clang --gcc-toolchain=path/to/gcc/usr /tmp/main.cpp -lstdc++ -o /tmp/main
Now, I want to have a custom libc
too, so I thought using --sysroot
would be right way of doing it:
clang --sysroot=path/to/sysroot --gcc-toolchain=path/to/gcc/usr /tmp/main.cpp -lstdc++ -o /tmp/main
However this leads to a linker error: cannot find libstdc++
nor libgcc_s
:
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lgcc_s
Inspecting the linker command, I notice that without --sysroot
, Clang adds this line:
-Lpath/to/gcc/usr/lib/gcc/x86_64-pc-linux-gnu/7.5.0/../../../../lib64
Whereas if I do add --sysroot
, clang does not add that line. Indeed that folder is where the missing libraries are to be found.
Is this expected behavior? I could add the -L
line myself but I thought it was very neat that it was automagically taken care of by --gcc_toolchain
.
Thanks!