linkerclanglld

argument unused during compilation: '-fuse-ld=lld'


I have successfully built clang and lld from source, and both are now available under my .../llvm-project/build/bin directory.

Following lld documentation, I am now trying to pass -fuse-ld=lld command line directive to clang to force it to use lld instead of system's default linker (which is GNU ld if I am not mistaken) as follows:

../llvm-project/build/bin/clang -fuse-ld=lld -c test.c

But I get this warning:

clang-16: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]

Which I suppose means lld was not used as the linker despite me asking for it.

What am I doing wrong?

I am on Ubuntu 22.04.1 LTS x86_64 and I am using clang version 16.0.0 and lld 16.0.0.


Solution

  • What am I doing wrong?

    This: clang -fuse-ld=lld -c test.c is a compilation command. It does not perform any linking.

    This argument: -fuse-ld=lld is telling the compiler driver which linker to use at link time.

    You told the driver:

    1. to not do linking (the -c argument) and
    2. to use lld for linking in the same command

    The driver has no choice but to ignore your second instruction, since it's not going to do any linking, and that's what the warning is all about.

    You can safely ignore this warning, but a better solution is to pass the -fuse-ld=lld argument only to the link stage, and not to any compile stages.