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:

12672 questions
145
votes
2 answers

What happens to global and static variables in a shared library when it is dynamically linked?

I'm trying to understand what happens when modules with globals and static variables are dynamically linked to an application. By modules, I mean each project in a solution (I work a lot with visual studio!). These modules are either built into…
Raja
  • 2,386
  • 4
  • 17
  • 27
141
votes
20 answers

error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj

I have read a lot of solutions to my problem but none helped. I tried clean, rebuild. Reinstalled visual 2010 and change from professional to ultimate. But still I dont know why I have this error. My project look like this: 1 Exe Solution to test…
Qbunia
  • 1,483
  • 2
  • 11
  • 13
137
votes
10 answers

Is it feasible to compile Python to machine code?

How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code? Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves…
Andy Balaam
  • 5,583
  • 5
  • 31
  • 34
133
votes
6 answers

How do I determine the target architecture of static library (.a) on Mac OS X?

I'm interested in verifying if a given iPhone static library has been built for ARM or Intel. It's more curiosity than anything. Is there some kind of Mac OS X or BSD specific tool to do this? This post gives an example in Linux.
Justicle
  • 13,619
  • 13
  • 66
  • 91
132
votes
2 answers

Small Haskell program compiled with GHC into huge binary

Even trivially small Haskell programs turn into gigantic executables. I've written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge…
user181351
132
votes
4 answers

How can I link to a specific glibc version?

When I compile something on my Ubuntu Lucid 10.04 PC it gets linked against glibc. Lucid uses 2.11 of glibc. When I run this binary on another PC with an older glibc, the command fails saying there's no glibc 2.11... As far as I know glibc uses…
falstaff
  • 2,675
  • 2
  • 23
  • 24
127
votes
8 answers

Visual C++: How to disable specific linker warnings?

I'm using a library from CGAL which during the linking stage of my code compilation produces a lot of linking warnings of this form: warning LNK4099: PDB 'vc80.pdb' was not found with 'gmp-vc80-mt-sgd.lib' or at 'vc80.pdb'; linking object as if no…
Ashwin Nanjappa
  • 68,458
  • 72
  • 198
  • 283
125
votes
1 answer

What does the -all_load linker flag do?

I can't find anywhere what the -all_load flag do when compiling Objective-C code. I have some issues uploading binaries to Apple, the they say it's because I didn't use this flag, but my code compiles even without it. Can some one help me with…
Guy Ephraim
  • 3,382
  • 3
  • 24
  • 29
125
votes
5 answers

Why am I getting "undefined reference to sqrt" error even though I include math.h header?

I'm very new to C and I have this code: #include #include int main(void) { double x = 0.5; double result = sqrt(x); printf("The square root of %lf is %lf\n", x, result); return 0; } But when I compile this with: gcc…
Ant's
  • 12,571
  • 21
  • 91
  • 141
122
votes
25 answers

Why does fatal error "LNK1104: cannot open file 'C:\Program.obj'" occur when I compile a C++ project in Visual Studio?

I've created a new C++ project in Visual Studio 2008. No code has been written yet; Only project settings have been changed. When I compile the project, I receive the following fatal error: fatal error LNK1104: cannot open file 'C:\Program.obj'
Josh Sklare
  • 3,784
  • 3
  • 20
  • 17
121
votes
4 answers

How do I make a fully statically linked .exe with Visual Studio Express 2005?

My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio 2005 Express edition. From time to time I have sent release .exe files to other people with pleasing results. However recently I made the disturbing…
Bill Forster
  • 5,835
  • 3
  • 24
  • 26
116
votes
3 answers

Is it safe to link C++17, C++14, and C++11 objects

Suppose I have three compiled objects, all produced by the same compiler/version: A was compiled with the C++11 standard B was compiled with the C++14 standard C was compiled with the C++17 standard For simplicity, let's assume all headers were…
ricab
  • 2,161
  • 3
  • 18
  • 26
114
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
  • 24,051
  • 18
  • 90
  • 141
110
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,173
  • 3
  • 8
  • 4
110
votes
2 answers

What is the -fPIE option for position-independent executables in gcc and ld?

How will it change the code, e.g. function calls?
osgx
  • 80,853
  • 42
  • 303
  • 470