Questions tagged [linker]

The linker is part of the toolchain for producing executables from source code written in compiled programming languages. It takes compiled object code in multiple files and produces a single, "linked", executable file from them.

Separately-compiled programming languages such as C and C++ rely on a linker to turn one or more object files and libraries into an executable. The linker resolves undefined symbol references in object files by linking them to symbol definitions in other object files and libraries. The linker also arranges variables and functions to assign them addresses in the final executable,

On Unix-like operating systems the linker is typically named ld and is often invoked automatically by the compiler as the last step in the compilation process.

Books about linkers:

13907 questions
129
votes
8 answers

static linking only some libraries

How can I statically link only a some specific libraries to my binary when linking with GCC? gcc ... -static ... tries to statically link all the linked libraries, but I haven't got the static version of some of them (eg: libX11).
peoro
  • 25,562
  • 20
  • 98
  • 150
127
votes
7 answers

What does "collect2: error: ld returned 1 exit status" mean?

I see the error collect2: error: ld returned 1 exit status very often. For example, I was trying to build the following snippet of code: void main() { char i; printf("ENTER i"); scanf("%c", &i); clrscr(); switch(i) { default: …
user3682120
  • 1,273
  • 2
  • 9
  • 4
121
votes
14 answers

What is compiler, linker, loader?

I wanted to know in depth meaning and working of compiler, linker and loader. With reference to any language preferably c++.
Sachin
  • 1,283
  • 3
  • 9
  • 4
119
votes
3 answers

Why do I get "unresolved external symbol" errors when using templates?

When I write C++ code for a class using templates and split the code between a source (CPP) file and a header (H) file, I get a whole lot of "unresolved external symbol" errors when it comes to linking the final executible, despite the object file…
dlanod
  • 8,664
  • 8
  • 54
  • 96
118
votes
10 answers

What is the equivalent of Linux's ldd on windows?

What is the equivalent of Linux's ldd on Windows?
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
117
votes
5 answers

How to specify preference of library path?

I'm compiling a c++ program using g++ and ld. I have a .so library I want to be used during linking. However, a library of the same name exists in /usr/local/lib, and ld is choosing that library over the one I'm directly specifying. How can I fix…
Heinrich Schmetterling
  • 6,614
  • 11
  • 40
  • 56
112
votes
6 answers

What is __gxx_personality_v0 for?

This is a second-hand question from an OS development site, but it made me curious since I couldn't find a decent explanation anywhere. When compiling and linking a free-standing C++ program using gcc, sometimes a linker error like this…
Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
111
votes
16 answers

Splitting templated C++ classes into .hpp/.cpp files--is it possible?

I am getting errors trying to compile a C++ template class which is split between a .hpp and .cpp file: $ g++ -c -o main.o main.cpp $ g++ -c -o stack.o stack.cpp $ g++ -o main main.o stack.o main.o: In function `main': main.cpp:(.text+0xe):…
exscape
  • 2,185
  • 4
  • 21
  • 25
109
votes
6 answers

How to add include and lib paths to configure/make cycle?

I need a place to install libraries in a linux box I have no su access to. I'm using ~/local[/bin,/lib,/include], but I don't know how can I tell ./configure to look for libraries there (particularly, I'm trying to compile emacs, which needs libgif,…
Lacrymology
  • 2,269
  • 2
  • 20
  • 28
105
votes
5 answers

What does the "no version information available" error from linux dynamic linker mean?

In our product we ship some linux binaries that dynamically link to system libraries like "libpam". On some customer systems we get the following error on stderr when the program runs: ./authpam: /lib/libpam.so.0: no version information available…
Matt Doran
103
votes
9 answers

Compilation fails with "relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object"

I'm trying to compile this source code from the makefile in a VPS, but its not working. The VPS is a 64 Cent OS Here's the full error # make gcc -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/amx/*.c g++ -c -O3 -w -DLINUX -I../SDK/amx/ ../SDK/*.cpp g++ -c…
user1667191
  • 2,387
  • 6
  • 20
  • 25
101
votes
1 answer

What are the --start-group and --end-group command line options?

What is the purpose of those command line options? Please help to decipher the meaning of the following command line: -Wl,--start-group -lmy_lib -lyour_lib -lhis_lib -Wl,--end-group -ltheir_lib Apparently it has something to do with linking, but…
pic11
  • 14,267
  • 21
  • 83
  • 119
99
votes
9 answers

static variables in an inlined function

I have a function that is declared and defined in a header file. This is a problem all by itself. When that function is not inlined, every translation unit that uses that header gets a copy of the function, and when they are linked together there…
Dirk Groeneveld
  • 2,547
  • 2
  • 22
  • 23
98
votes
2 answers

combine two GCC compiled .o object files into a third .o file

How does one combine two GCC compiled .o object files into a third .o file? $ gcc -c a.c -o a.o $ gcc -c b.c -o b.o $ ??? a.o b.o -o c.o $ gcc c.o other.o -o executable If you have access to the source files the -combine GCC flag will merge the…
Lucian Adrian Grijincu
  • 2,491
  • 2
  • 18
  • 18
96
votes
5 answers

What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?

What is inside of a .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library? How come there is no need for a .lib file in dynamically linked dynamic library and also that in static linking, the .lib file…
Sulla
  • 7,631
  • 9
  • 45
  • 71