KawaiKx
KawaiKx

Reputation: 9918

how does a linker functions?

In static linking, how does the linker knows which library file to link the user's compiled object code against? I mean the header only contains the function protoytpes that may be used in the source code, not the library file name.. isn't it?

Upvotes: 0

Views: 134

Answers (2)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272487

That's why you provide the linker with a list of libraries to link against!

e.g. for GCC, you might do something like:

gcc my_prog.o -lm -lpthread -o my_prog

Here, the -l flag is used to tell the linker to link against libm and libpthread.

Upvotes: 2

andrewdski
andrewdski

Reputation: 5505

It gets a list of libraries from the command line. The specifics will depend on the OS and the compiler.

Upvotes: 1

Related Questions