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
72
votes
5 answers

ld linker question: the --whole-archive option

The only real use of the --whole-archive linker option that I have seen is in creating shared libraries from static ones. Recently I came across Makefile(s) which always use this option when linking with in house static libraries. This of course…
jasmeet
72
votes
12 answers

GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'

I'm setting up a C++ project, on Ubuntu x64, using Eclipse-CDT. I'm basically doing a hello world and linking to a commerical 3rd party library. I've included the header files, linked to their libraries, but I still get linker errors. Are there…
waterlooalex
  • 13,642
  • 16
  • 78
  • 99
71
votes
8 answers

The State of Linkers for .NET apps (aka "Please Sir, May I have a Linker" 2009 edition)

Many people here are probably familiar with one of Joel Spolsky most popular blog posts, Please Sir, May I Have a Linker, where he cries out for a way to remove dependencies on the .NET framework so a stand-alone application can be developed and…
Robert P
  • 15,707
  • 10
  • 68
  • 112
71
votes
7 answers

Static variables initialisation order

C++ guarantees that variables in a compilation unit (.cpp file) are initialised in order of declaration. For number of compilation units this rule works for each one separately (I mean static variables outside of classes). But, the order of…
Dmitry Khalatov
  • 4,313
  • 3
  • 33
  • 39
71
votes
5 answers

Get list of static libraries used in an executable

Since ldd lists only the dynamic libraries, is there a way to extract the information about the static libraries used to create the executable?
Saurabh
  • 807
  • 1
  • 8
  • 7
69
votes
3 answers

What is the difference between -I and -L in makefile?

What is the usage of the -I and -L flags in a makefile?
MainID
  • 29,070
  • 19
  • 57
  • 70
69
votes
17 answers

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

I don't know what's wrong with it.. I can't find where the error is, commenting out the implementation doesn't resolve the error either. Header File #ifndef MAIN_SAVITCH_SEQUENCE_H #define MAIN_SAVITCH_SEQUENCE_H #include // Provides…
Caleb Jares
  • 6,163
  • 6
  • 56
  • 83
68
votes
6 answers

Is /usr/local/lib searched for shared libraries?

Is /usr/local/lib searched for shared libraries ? I have this error: [Leo@chessman ~]$ whereis ffmpeg ffmpeg: /usr/local/bin/ffmpeg [Leo@chessman ~]$ ffmpeg ffmpeg: error while loading shared libraries: libavcore.so.0: cannot open shared object…
Leo Izen
  • 4,165
  • 7
  • 37
  • 56
68
votes
6 answers

Why aren't my compile guards preventing multiple definition inclusions?

I have a header file x.h which is included by more than one *.c source files. This header file has some structure variables defined. I have put multiple inclusion prevention guard at the beginning of the header file as: #ifndef X_H #define…
goldenmean
  • 18,376
  • 54
  • 154
  • 211
68
votes
2 answers

VA (Virtual Address) & RVA (Relative Virtual Address)

A file that is given as input to the linker is called Object File. The linker produces an Image file, which in turn is used as input by the loader. A blurb from "Microsoft Portable Executable and Common Object File Format Specification" RVA…
claws
  • 52,236
  • 58
  • 146
  • 195
65
votes
2 answers

How could I graphically display the memory layout from a .map file?

My gcc build toolchain produces a .map file. How do I display the memory map graphically?
JeffV
  • 52,985
  • 32
  • 103
  • 124
63
votes
8 answers

Duplicate symbol issues

During a refactor of an iOS project, I ran into this bear of a bug. During the linking phase, I get this message: ld: duplicate symbol _OBJC_IVAR_$_TinCanViewController.currentViewController in /path/to/TinCanViewController-E98A666B7AF2673A.o and…
drewww
  • 2,485
  • 4
  • 22
  • 24
63
votes
1 answer

Weak symbol aliases on OS X similar to those on Linux, or a closest equivalent?

What I do When writing shared libraries for Linux, I tend to pay attention to relocations, symbol visibility, GOT/PLT etc. When applicable, I am trying to avoid calling PLT stubs when functions from the same library call each other. For example,…
user405725
62
votes
6 answers

What do R_X86_64_32S and R_X86_64_64 relocation mean?

Got the following error when I tried to compile a C application in 64-bit FreeBSD: relocation R_X86_64_32S can not be used when making a shared object; recompile with -fPIC What is R_X86_64_32S relocation and what is R_X86_64_64? I've googled…
Raj
  • 4,342
  • 9
  • 40
  • 45
62
votes
11 answers

ld: file not found: linker command failed with exit code 1

I've got the following error when building the project in Xcode: ld: file not found /Users/MacBookPro/Library/Developer/Xcode/DerivedData/Social_Events-cfnteabiivwfdzcoulzznhmgobhy/Build/Products/Debug-iphoneos/Social_Events.app/Social_Events …
user4200570