7

The problem is, I've found out that Mac OS X has an dyld (as I understood a dynamic linker) but also a simple linker ld (as I understood a static one).

The question is: Is it really so ? Two linkers? One static and one dynamic ?

Why they've decided to have two ? Linux has only one linker (ld) which does both static and dynamic linking.

denis631
  • 1,765
  • 3
  • 17
  • 38

1 Answers1

7

You have misunderstood the meaning of "linking". Or, thought of another way, you haven't realized it has two meanings.

If it helps, think of dyld as the dynamic loader rather than "linker". dyld is the program which loads the dynamic libraries referenced by an executable into the process's address space. It still involves linking because it requires the resolution of symbol references.

You never invoke dyld as part of a build procedure. You always use ld or, more typically, you ask the compiler to link your program and it invokes ld on your behalf. dyld is only used at run time.

You're incorrect when you assert that Linux doesn't have this distinction. Linux has a dynamic loader, ld.so, which is distinct from the static linker, ld.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • From the : **man ld.so** The programs ld.so and ld-linux.so* find and load the shared libraries needed by a program, prepare the program to run, and then run it. The difference between these 2 is that ld.so works with a.out old format and ld-linux.so with the newer ELF binary format. So we use the ld-linux.so when we click on our binary in order to execute it , then what kind of "ld" we use while compiling a certain module ? could you give me the path to this "ld" ? – Oleg Mar 30 '15 at 07:02
  • @Oleg If you run `which ld` it will tell you. – Mike Kinghan Mar 30 '15 at 10:57
  • 1
    I understand you don't invoke `dyld` in the build process. But ,do you ever have to invoke it during run time? And I suppose no variable is passed directly to `dyld`, instead you only export some _environmental_ variables. Is that right? – mfaani Feb 18 '23 at 20:00