Why does clang/llvm on windows require Visual Studio's Link.exe?
Asked Answered
M

2

11

According to LLVM's Getting Started (Windows) site:

... Clang can be used to emit bitcode, directly emit object files or even linked executables using Visual Studio’s link.exe.

Why is the use of Link.exe on Windows necessary? And, for that matter, what is used on Mac/Linux? Further down it says:

Compile the program to object code using the LLC code generator:
    C:\..> llc -filetype=obj hello.bc
Link to binary using Microsoft link:
    C:\..> link hello.obj -defaultlib:libcmt

Why can't LLC perform that last step? LLI seems to work fine so I assume that it interoperates with link.exe somehow under the hood - why can't LLC?

Mortarboard answered 14/1, 2013 at 4:46 Comment(0)
K
13

Because no one has written a linker for LLVM.

There is a project to do so (called, unimaginatively lld) but it's not ready yet.

See http://lld.llvm.org for more details.

On the mac, people use Apple's linker, ld.

On Linux, most people use the gnu linker, usually (also) named ld

Kirby answered 14/1, 2013 at 5:20 Comment(5)
I guess this means LLVM doesn't do LTO?Stefaniestefano
@Mehrdad: LLVM does LTO on IR level. But even if an executable is produced from a single .s file, it still has to be linked.Lactiferous
@Mehrdad, both gold and Mac ld can use LLVM plugin for LTO.Mendelson
lld is supported on windows in the meantimeFlatto
Is this answer still up to date? The default LLVM install still assumes you're using Visual Studio, but is LLD more stable now and seems to be ready as a drop in replacement (assuming with some default config changes)?Lewan
H
5

Try MinGW-W64's ld. I've been using it with llvm's clang instead of VS tools that I used for building clang in the first place.

Heulandite answered 4/3, 2013 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.