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

ld: Using -rpath,$ORIGIN inside a shared library (recursive)

I just made a basic example of using ld's -rpath option with $ORIGIN here (see 2nd response for a working version). I'm trying to create an example where main.run links to foo.so, which in turn links to bar.so, all using rpath and $ORIGIN. The…
Simon
  • 623
  • 1
  • 8
  • 13
30
votes
1 answer

Function-Level Linking (/Gy switch in VC++) - What is it good for?

What is there to gain from the use of this switch in a large VS solution (200 VC projects)? From what I understand this mainly affects the size of the resulting binaries; but aside from smaller binaries, could FLL also help in reducing dependencies…
Assaf Lavie
  • 73,079
  • 34
  • 148
  • 203
30
votes
6 answers

Why are static and dynamic linkable libraries different?

If both of them contain compiled code, why can't we load the "static" files at runtime and why can't we link with the dynamic libraries at compile time? Why is there a need for separate formats to contain "standalone" code? What needs to be stored…
Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
30
votes
4 answers

Linking Libraries in Xcode

I'm using a powerbook (osx 10.5) and recently downloaded and installed FFTW 3.2 (link text). I've been able to compile and run some simple programs based on the online tutorial using the terminal: g++ main.cpp -lfftw3 -lm However, I can't get the…
Dan
30
votes
13 answers

LNK1318: Unexpected PDB error; OK (0)

I'm trying to link against a library (libcef_wrapper_dll.lib) that was built with the /MDd flag. My application is build with /MDd and /CLR so should be compatible. The project compiles fine but when linking I get the very unhelpful error below: …
chillitom
  • 24,888
  • 17
  • 83
  • 118
30
votes
3 answers

correct usage of rpath (relative vs absolute)

When building a binary or library, specifying the rpath, i.e. -Wl,rpath, tells the linker where to find the required library at runtime of the binary. What is the UNIX philosphy regarding absolute and relative paths here? Is it better…
mattmilten
  • 6,242
  • 3
  • 35
  • 65
30
votes
3 answers

Undefined reference to global variable during linking

I am trying to compile a program which is divided into 3 modules, corresponding to 3 source files: a.c, b.c, and z.c. z.c contains the main() function, which calls functions in a.c and b.c. Furthermore, a function in a.c calls a function in b.c, and…
freieschaf
  • 530
  • 1
  • 5
  • 13
30
votes
3 answers

Why does the C++ linker allow undefined functions?

This C++ code, perhaps surprisingly, prints out 1. #include std::string x(); int main() { std::cout << "x: " << x << std::endl; return 0; } x is a function prototype, which seems to be viewed as a function pointer, and C++…
chmullig
  • 13,006
  • 5
  • 35
  • 52
30
votes
3 answers

Linking using g++ fails searching for -lstdc++

I'm trying to use someone else's Makefile to complile a very simple c++ library. The makefile is as follows: JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux all: rm -f ../dist/libUtils.so g++…
jwoolard
  • 6,024
  • 9
  • 37
  • 37
30
votes
5 answers

Difference between load-time dynamic linking and run-time dynamic linking

When loading programs into memory, what is the difference between load-time dynamic linking and run-time dynamic linking?
jennyson
  • 341
  • 2
  • 4
  • 4
30
votes
4 answers

How do I create a dynamic library (dylib) with Xcode?

I'm building few command-line utilities in Xcode (plain C, no Cocoa). I want all of them to use my customized version of libpng, and I want to save space by sharing one copy of the library among all executables (I don't mind re-distributing .dylib…
Kornel
  • 97,764
  • 37
  • 219
  • 309
30
votes
1 answer

GCC(/Clang): Merging functions with identical instructions (COMDAT folding)

Just curious, do the GCC or Clang toolsets implement the equivalent of MSVC's identical COMDAT folding (ICF) currently? If not, are there any plans to? I can't seem to find any recent authoritative links on the subject other than old GCC mailing…
Stephen Lin
  • 5,470
  • 26
  • 48
30
votes
5 answers

Linker error on a C project using Eclipse

I want create a project for the STM32F217IG microcontroller. So I installed Eclipse and the GNU for ARM embedded GCC cross compiler. I don't think it is the Code Sourcery one. I used it, because it supports floating point and Code Sourcery does…
damien
  • 415
  • 1
  • 6
  • 13
30
votes
2 answers

gcc will not properly include math.h

Here is a minimal example outlining my problem test.c: #include #include main () { fmod ( 3, 2 ); } And here is the command I am issuing to compile test.c gcc -lm test.c -o test And here is the output I get when I issue the…
puk
  • 16,318
  • 29
  • 119
  • 199
30
votes
3 answers

How do I add a lib file to link in Visual C++ 2010?

I've found the Additional Dependencies thing on Visual C++ 2010, but I can't seem to find any option of adding new .lib files when I go to . I need to add wsock32.lib to link with my file, how do I make it happen? Thanks!
Zakum
  • 491
  • 1
  • 5
  • 6