Welgriv
Welgriv

Reputation: 833

How to specify the default linker for Clang when compiling from source?

I am in the process of compiling Clang from source on my system. However, I have multiple ld (linker) binaries available:

After successfully compiling Clang, it defaults to using the linker located at /another/location/ld. However, I want Clang to use the linker at /usr/bin/ld by default.

Is there a specific configuration option or a method to specify the default linker during the Clang compilation process?

I know there is the LLVM_USE_LINKER CMake variable but in my understanding it specify the linker that will be used to actually compile Clang, and not the one the it will be used to compile let's say user code afterward.

Upvotes: 1

Views: 48

Answers (1)

J. Nolan Faught
J. Nolan Faught

Reputation: 464

Although not explicitly documented in the Linux manpage or on the LLVM website, the GCC-compatible flag -fuse-ld allows you to point clang to a linker.

$ which ld
/usr/bin/ld
$ clang -fuse-ld=/usr/bin/ld main.c -o main

If you ever need to know exactly what linker or assembler clang is using, the -v flag shows all invocations made during compilation.

Upvotes: -1

Related Questions