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
39
votes
18 answers

error LNK2005: _DllMain@12 already defined in MSVCRT.lib

I am getting this linker error. mfcs80.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRT.lib(dllmain.obj) Please tell me the correct way of eliminating this bug. I read solution on microsoft support site about this bug but…
Priyanka Mishra
  • 10,400
  • 18
  • 62
  • 75
39
votes
4 answers

g++ linking order dependency when linking c code to c++ code

Prior to today I had always believed that the order that objects and libraries were passed to g++ during the linking stage was unimportant. Then, today, I tried to link from c++ code to c code. I wrapped all the C headers in an extern "C" block but…
Gearoid Murphy
  • 11,834
  • 17
  • 68
  • 86
39
votes
2 answers

Relation between object file and shared object file

what is the relation between shared object(.so) file and object(.o) file? can you please explain via example?
ASHOK
  • 1,475
  • 4
  • 14
  • 14
38
votes
8 answers

Undefined reference to 'vtable for xxx'

takeaway.o: In function `takeaway': project:145: undefined reference to `vtable for takeaway' project:145: undefined reference to `vtable for takeaway' takeaway.o: In function `~takeaway': project:151: undefined reference to `vtable for…
TacticalMin
  • 791
  • 2
  • 7
  • 18
38
votes
7 answers

No Linker option in Visual Studio Project Properties

I'm trying to add a library to a Visual Studio C++ project, however, when I go to project properties I only have options for, Common Properties Startup Project Project Dependencies Debug Source File Configuration Properites …
user346443
  • 4,672
  • 15
  • 57
  • 80
38
votes
6 answers

Can gcc use multiple cores when linking?

So when compiling tons of source files with GCC one can use -j to use all available cores. But what about the linker? Is there a similar option to speed up linking or does GCC not support multi-threading? In some larger projects it can really take a…
Danvil
  • 22,240
  • 19
  • 65
  • 88
38
votes
4 answers

Is there a way to get gcc to output raw binary?

Is there a set of command-line options that will convince gcc to produce a flat binary file from a self-contained source file? For example, suppose the contents of foo.c are static int f(int x) { int y = x*x; return y+2; } No external…
I. J. Kennedy
  • 24,725
  • 16
  • 62
  • 87
38
votes
4 answers

How do I determine the fastest link order?

I have about 50 different static libraries being linked into my c++ project and the linking takes on average 70s. I've found that moving around with the link order of the libraries changes this time. This is expected I guess if the linker doesn't…
owagh
  • 3,428
  • 2
  • 31
  • 53
37
votes
3 answers

linking objective-c categories in a static library

I am developing a plugin for an iOS application. I am compiling it into a .a file which is then used by the main xcode project. So far I have create a category of the UIDevice class in this library. When I run the main project using this library it…
micken
  • 583
  • 1
  • 6
  • 7
37
votes
1 answer

How to link with the GNU gold linker instead of ld in Haskell

My Haskell project spends lots of time in Linking dist/build/myapp/myapp ... and also in loading shared libraries when executing TemplateHaskell code. I suspect this is because ld is slow. How can I improve link times by switching to the gold…
nh2
  • 24,526
  • 11
  • 79
  • 128
37
votes
5 answers

Difference between code object and executable file

I'm a C++ beginner and I'm studying the basics of the language. There is a topic in my book about the compiler and my problem is that I can not understand what the text wants to say: C++ is a compiled language so you need to translate the source…
Piero Borrelli
  • 1,151
  • 2
  • 11
  • 15
37
votes
8 answers

difference between dynamic loading and dynamic linking?

Routine is not loaded until it is called. All routines are kept on disk in a re-locatable load format. The main program is loaded into memory & is executed. This is called Dynamic Linking. Why this is called Dynamic Linking? Shouldn't it be…
Luv
  • 5,381
  • 9
  • 48
  • 61
36
votes
3 answers

Linker error when accessing application module in UI tests in Xcode 7.1

I'm trying to implement some UI tests in my project. Everything goes fine as long as I keep it simple: record the test case, add some asserts, then run the test. This works fine, however when I try to access the application module from inside my…
lawicko
  • 7,246
  • 3
  • 37
  • 49
36
votes
3 answers

How to list exported functions in a shared lib on Ubuntu

I have just built a shared lib on Ubuntu, and when I attempt to use the function, the application that loads the library is reporting 'xxx' symbol not found. I want to check (i.e. list) the functions that are exported by my library so I can…
Stick it to THE MAN
  • 5,621
  • 17
  • 77
  • 93
36
votes
3 answers

CMake and Static Linking

I'm using CMake in a project, and I'm trying to statically link some libraries. I've set: set(BUILD_SHARED_LIBS OFF) set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static") set_target_properties(icarus PROPERTIES…
Ælex
  • 14,432
  • 20
  • 88
  • 129