www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Choosing a non-default linker for dmd (via dub)

reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
The line



in dub.sdl

enables me to change linker for LDC.

Is it possible to choose a specific linker for DMD aswell in a 
similar way?

I only find the flag `-L` that sets flags but no linker 
executable.

One way is to link

     /usr/bin/ld

to either

     /usr/bin/ld.gold

or

     /usr/bin/ld.lld

but it would be nice to be able to do this from the dub.sdl or 
the command-line call to dub.
Jul 12 2020
next sibling parent WebFreak001 <d.forum webfreak.org> writes:
On Sunday, 12 July 2020 at 16:36:09 UTC, Per Nordlöw wrote:
 The line



 in dub.sdl

 enables me to change linker for LDC.

 Is it possible to choose a specific linker for DMD aswell in a 
 similar way?

 I only find the flag `-L` that sets flags but no linker 
 executable.

 One way is to link

     /usr/bin/ld

 to either

     /usr/bin/ld.gold

 or

     /usr/bin/ld.lld

 but it would be nice to be able to do this from the dub.sdl or 
 the command-line call to dub.
dub links using the compiler, so it basically just runs `dmd [flags] [files-to-link]` In the DMD documentation you can see that it just runs gcc: https://dlang.org/dmd-linux.html#linking Personally I always `ln -s /usr/bin/ld.gold /usr/local/bin/ld` to make ld.gold the default.
Jul 13 2020
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2020-07-12 18:36, Per Nordlöw wrote:
 The line
 

 
 in dub.sdl
 
 enables me to change linker for LDC.
 
 Is it possible to choose a specific linker for DMD aswell in a similar way?
 
 I only find the flag `-L` that sets flags but no linker executable.
 
 One way is to link
 
      /usr/bin/ld
 
 to either
 
      /usr/bin/ld.gold
 
 or
 
      /usr/bin/ld.lld
 
 but it would be nice to be able to do this from the dub.sdl or the 
 command-line call to dub.
There's an environment variable "CC" that can be used to select which C compiler is used. Is there any equivalence for selecting the linker, "LD" perhaps? -- /Jacob Carlborg
Jul 15 2020
parent kinke <kinke gmx.net> writes:
On Wednesday, 15 July 2020 at 11:38:47 UTC, Jacob Carlborg wrote:
 There's an environment variable "CC" that can be used to select 
 which C compiler is used. Is there any equivalence for 
 selecting the linker, "LD" perhaps?
You normally just add -fuse-ld=gold to the C compiler cmdline, e.g., via -Xcc=-fuse-ld=gold in the DMD cmdline.
Jul 15 2020