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
32
votes
6 answers

Reasons to use Static functions and variables in C

I wonder about the use of the static keyword as scope limiting for variables in a file, in C. The standard way to build a C program as I see it is to: have a bunch of c files defining functions and variables, possibly scope limited with…
Gauthier
  • 40,309
  • 11
  • 63
  • 97
32
votes
1 answer

Windows & C++: extern & __declspec(dllimport)

What is the difference/relationship between "extern" and "__declspec(dllimport")? I found that sometimes it is necessary to use both of them, sometimes one is enough. Am I right that: "extern" is for statically linked…
liori
  • 40,917
  • 13
  • 78
  • 105
32
votes
7 answers

Link with an older version of libstdc++

After installing a new build machine, I found out it came with 6.0.10 of the standard C++ library -rw-r--r-- 1 root root 1019216 2009-01-02 12:15 libstdc++.so.6.0.10 Many of our target machines, however, still use an older version of libstdc++,…
Pieter
  • 17,435
  • 8
  • 50
  • 89
32
votes
4 answers

XCode 5 GM linker error: too many compact unwind infos in function anon for architecture i386

We just updated to XCode 5 GM, and a project (iPhone only targeted at iOS 7) that built fine under DP 5 now gives the error: ld: in…
dang
  • 587
  • 1
  • 5
  • 10
32
votes
4 answers

.bss vs COMMON: what goes where?

From my book: .bss: Uninitialized global C variables COMMON: Uninitalized data objects that are not yet allocated I have to say, I don't quite see a clear distinction. I don't even quite understand what an uninitizalied, non-allocated data…
gone
  • 2,587
  • 6
  • 25
  • 32
32
votes
2 answers

What is the difference between .LIB and .OBJ files? (Visual Studio C++)

I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the…
32
votes
4 answers

What are possible causes of "failed to map segment from shared object: operation not permitted", and how to debug?

I have two executables, both cross compiled to run in Android. I have put both on the device in the same directory. I have put all the shared libraries that they are dependent on in the same directory, including ld-linux.so.3. I run the…
corbin
  • 1,446
  • 2
  • 27
  • 40
32
votes
2 answers

Linking C++ code with 'gcc' (without g++)

Hi all: quick question: I'm in a situation where it would be useful to generate my C++ executable using only 'gcc' (without g++). Reason for this is that I have to submit the code to an automatic submission server which doesn't recognize the 'g++'…
Rafael Almeida
  • 10,352
  • 6
  • 45
  • 60
31
votes
4 answers

What is "object" in "object file" and why is it called this way?

I was asked a question: "What is an 'object file'?". After looking at Wiki, I only know that it contains objects. But what are those objects and why someone called them that way?
sthlm58
  • 1,142
  • 1
  • 9
  • 28
31
votes
2 answers

Android NDK: Link using a pre-compiled static library

I'm trying to port Jnetpcap to Android in order to use it for parsing .pcap files. Jnetpcap is a java wrapper for libpcap which uses JNI. I have compiled libpcap as a static library using the android's source code tree. When compiling Jnetpcap as a…
Jimix
  • 1,539
  • 3
  • 15
  • 20
31
votes
3 answers

How does the linker handle identical template instantiations across translation units?

Suppose I have two translation-units: foo.cpp void foo() { auto v = std::vector(); } bar.cpp void bar() { auto v = std::vector(); } When I compile these translation-units, each will instantiate std::vector. My question is: how…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
31
votes
4 answers

Compiling 32-bit vs 64-bit project using CMake

How do I specify that CMake should use a different link_directories value depending on whether the target is 32-bit or 64-bit? For example, 32-bit binaries need to link with 32-bit Boost, 64-bit binaries need to link with 64-bit Boost.
Gili
  • 86,244
  • 97
  • 390
  • 689
31
votes
5 answers

What are practical applications of weak linking?

Using special compiler commands a symbol can be declared weak. According to Wikipedia: a weak symbol is a symbol definition in an object file or dynamic library that may be overridden by other symbol definitions In what scenarios or for what…
Bernhard Kausler
  • 5,119
  • 3
  • 32
  • 36
30
votes
1 answer

gcc debug symbols (-g flag) vs linker's -rdynamic option

glibc provides backtrace() and backtrace_symbols() to get the stack trace of a running program. But for this to work the program has to be built with linker's -rdynamic flag. What is the difference between -g flag passed to gcc vs linker's -rdynamic…
Manohar
  • 3,865
  • 11
  • 41
  • 56
30
votes
4 answers

Undefined symbols: "_OBJC_CLASS_$ error

I've been looking through countless posts about this error: Undefined symbols: "_OBJC_CLASS_$_BoxView", referenced from: objc-class-ref-to-BoxView in ViewMovingViewController.o ld: symbol(s) not found collect2: ld returned 1 exit status BoxView…
cms
  • 301
  • 1
  • 3
  • 3