admin管理员组

文章数量:1289537

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

  • /usr/bin/ld
  • /another/location/ld

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.

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

  • /usr/bin/ld
  • /another/location/ld

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.

Share Improve this question asked Feb 20 at 12:48 WelgrivWelgriv 83311 silver badges25 bronze badges 2
  • Is there some reason you don't want clang to default to the LLVM linker lld? Depending on your install environment and configuration, lld should be built along with clang and will act as the default linker. – J. Nolan Faught Commented Feb 22 at 2:57
  • Yes, there is specific reason I won't elaborate here, but non-the-less it keeps point to /another/location/ld, so even if I would like it to use lld I don't know how to... – Welgriv Commented Feb 24 at 9:10
Add a comment  | 

1 Answer 1

Reset to default -1

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.

本文标签: llvmHow to specify the default linker for Clang when compiling from sourceStack Overflow