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
62
votes
4 answers

Unresolved external symbol LNK2019

First of all, I know this question is all over this site but I have looked at almost all of them and can't seem to find out what is wrong. This is in VS 2012. Thanks. //Socket.h #pragma once #include #include using…
Iowa15
  • 3,027
  • 6
  • 28
  • 35
61
votes
3 answers

Use both static and dynamically linked libraries in gcc

I need to distribute a binary that will run on as many x86 Linux distributions as possible. That means that I have to statically link some libraries, like glibc, because the user might not have the version I use. Other libraries have to be…
Steve Hanov
  • 11,316
  • 16
  • 62
  • 69
61
votes
5 answers

What does the "Link Library Dependency" linker option actually do in Visual Studio 2010 - 2015 and upwards?

Up to VS2008, you set your native C++ project dependencies up in the solution file (Project Dependencies ...) and if (by default) the Linker Option Properties -> Linker -> General : Link Library Dependencies = Yes is set, the Visual Studio Build…
61
votes
1 answer

Can I mix static and shared-object libraries when linking?

I have a C project that produces ten executables, all of which I would like to be linked in statically. The problem I am facing is that one of these executables uses a 3rd-party library of which only the shared-object version is available. If I pass…
SiegeX
  • 135,741
  • 24
  • 144
  • 154
61
votes
2 answers

gcc: undefined reference to

I would like to compile this. program.c #include int main(){ int i = avpicture_get_size(AV_PIX_FMT_RGB24,300,300); } Running this gcc -I$HOME/ffmpeg/include program.c gives error /tmp/ccxMLBme.o: In function…
jamie_y
  • 1,719
  • 2
  • 13
  • 20
60
votes
3 answers

What does KEEP mean in a linker script?

The LD manual does not explain what the KEEP command does. Below is a snippet from a third-party linker script that features KEEP. What does the KEEP command do in ld? SECTIONS { .text : { . = ALIGN(4); _text = .; …
Randomblue
  • 112,777
  • 145
  • 353
  • 547
60
votes
5 answers

How to static link on OS X

I'm trying to link to a static library on OS X. I used the -static flag in the gcc command but I get the following error message: ld_classic: can't locate file for: -lcrt0.o collect2: ld returned 1 exit status I looked in the man pages and it…
Frank
60
votes
5 answers

Calling Haskell from C++ code

I'm currently writing an app in C++ and found that some of its functionality would be better written in Haskell. I've seen instructions on calling Haskell from C code, but is it possible to do the same with C++? EDIT: To clarify, what I'm looking…
Tomer Vromen
  • 1,762
  • 1
  • 13
  • 13
60
votes
5 answers

C++ extern keyword on functions. Why no just include the header file?

If I understand it correctly this means extern void foo(); that the function foo is declared in another translation unit. 1) Why not just #include the header in which this function is declared? 2) How does the linker know where to look for function…
user199421
  • 1,850
  • 2
  • 18
  • 18
59
votes
4 answers

MinGW linker error: winsock

I am using MinGW compiler on Windows to compile my C++ application with sockets. My command for linking looks like: g++.exe -Wall -Wno-long-long -pedantic -lwsock32 -o dist/Windows/piskvorky { there are a lot of object files } and I have also tried…
Gaim
  • 6,734
  • 4
  • 38
  • 58
58
votes
5 answers

Limiting visibility of symbols when linking shared libraries

Some platforms mandate that you provide a list of a shared library's external symbols to the linker. However, on most unixish systems that's not necessary: all non-static symbols will be available by default. My understanding is that the GNU…
rafl
  • 11,980
  • 2
  • 55
  • 77
58
votes
7 answers

How to resolve __gcov_init undefined reference issue when linking

I now work on C code coverage study and encountered following issue, GCC version 4.4.6: Added compiler flag CFLAGS = --coverage and linker option LDFLAGS := --coverage or LOCAL_LDLIBS := --coverage and got the error: undefined reference to…
lilingmzai
  • 601
  • 1
  • 5
  • 7
57
votes
6 answers

C++ Linker Error With Class static constexpr

I am compiling the following simple program with g++-4.6.1 --std=c++0x: #include struct S { static constexpr int X = 10; }; int main() { return std::min(S::X, 0); }; I get the following linker error: /tmp/ccBj7UBt.o: In…
Travis Gockel
  • 26,877
  • 14
  • 89
  • 116
57
votes
4 answers

Hierarchical ldd(1)

Due to using Gentoo, it often happens that after an update programs are linked against old versions of libraries. Normally, revdep-rebuild helps resolving that, but this time it's a dependency on a python library, and python-updater won't pick it…
Astro
  • 858
  • 1
  • 8
  • 8
56
votes
4 answers

When to use the Visual Studio Additional dependencies?

In C++, you got the header files (.h), the (.lib) files and the (.dll) files. In Visual Studio, you provide the location to search for these files in three different places: Configuration Properties => C/C++ => General => Additional Include…
user205834
  • 703
  • 1
  • 8
  • 7