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
28
votes
3 answers

Is the lld linker a drop-in replacement for ld and gold?

The linker from the LLVM project lld is currently developed with new features added week by week. Its developers promise that lld is faster than ld. How does it compete compared to gold? Is lld a drop-in replacement for ld? With gold there are some…
usr1234567
  • 21,601
  • 16
  • 108
  • 128
28
votes
2 answers

error when import zlib in iOS: symbol(s) not found collect2: ld

I have included in my iphone application and the source code I was mocking up the sample code of Molecules provided by Brad Larson, however, when I build the project, it returns the error as below. Can anyone point out for me whether this…
issac
  • 1,501
  • 6
  • 22
  • 29
28
votes
5 answers

How to make weak linking work with GCC?

There seem to be 3 ways of telling GCC to weak link a symbol: __attribute__((weak_import)) __attribute__((weak)) #pragma weak symbol_name None of these work for me: #pragma weak asdf extern void asdf(void) __attribute__((weak_import,…
Ben
28
votes
5 answers

Why does C++ linking use virtually no CPU?

On a native C++ project, linking right now can take a minute or two. Yet, during this time CPU drops from 100% during compilation to virtually zero. Does this mean linking is primarily a disk activity? If so, is this the main area an SSD would make…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
28
votes
7 answers

Any tool/software in windows for viewing ELF file format?

There are lots of PE file browsers. Here is a list of good ones if you are interested: PE File format viewers: PE Explorer http://www.pe-explorer.com/ PE VIew: http://www.magma.ca/~wjr/ PEBrowse Professional…
norris
  • 387
  • 1
  • 4
  • 6
28
votes
4 answers

Should variable definition be in header files?

My very basic knowledge of C and compilation process has gone rusty lately. I was trying to figure out answer to the following question but I could not connect compilation, link and pre-processing phase basics. A quick search on the Google did not…
Methos
  • 13,608
  • 11
  • 46
  • 49
28
votes
1 answer

MinGW creating dll.a files ? What type of library files are those?

I am fairly familiar with Windows and Linux libraries compilation but as for today when I have seen MinGW on my Windows machine threw out dll.a and .a files after OpenCV compilation I have started to seriously start thinking. These are my \lib…
Patryk
  • 22,602
  • 44
  • 128
  • 244
27
votes
2 answers

What does the "aw" flag in the section attribute mean?

In the following line of code (which declares a global variable), unsigned int __attribute__((section(".myVarSection,\"aw\",@nobits#"))) myVar; what does the "aw" flag mean? My understanding is that the nobits flag will prevent the variable from…
Duncan Drennan
  • 871
  • 2
  • 9
  • 21
27
votes
1 answer

Understanding the origin of a linker duplicate symbol error

I have a c++ program that compiled previously, but after mucking with the Jamfiles, the program no longer compiled and ld emitted a duplicate symbol error. This persisted after successively reverting to the original Jamfiles, running bjam clean,…
rcollyer
  • 10,475
  • 4
  • 48
  • 75
27
votes
4 answers

Templates: Use forward declarations to reduce compile time?

I have to deal with a library that consists of many templated classes, which are of course all implemented in header files. Now I'm trying to find a way to reduce the unbearably long compile times that come from the fact that I pretty much have to…
Frank
27
votes
1 answer

Linking Windows DLL files from static libraries using CMake without hand-crafting unresolved symbol names

The Situation I'm using Visual Studio 2008 SP1 (Professional Edition, both for 32-bit and 64-bit builds). I'm seeking a workaround to what I believe is a very unhelpful "limitation" in Visual Studio. I find it quite surprising that the Visual…
bgoodr
  • 2,744
  • 1
  • 30
  • 51
27
votes
7 answers

What is the Microsoft Visual Studio equivalent to GCC ld option --whole-archive

When linking a static library against an executable, unreferenced symbols are normally discarded. In my case some otherwise unused objects are used to register their respective classes into a factory and if the objects are discarded, this…
fschmitt
  • 3,478
  • 2
  • 22
  • 24
27
votes
2 answers

How to solve: The "Microsoft.VisualStudio.ProjectSystem.References.UnresolvedBuildDependencyProjectReference" reference could not be resolved?

In the Solution Explorer, the vcxproj projects that have references, show a warning symbol on each of the references associated with the project. When the reference is highlighted, the properties panel indicates that the Full Path is: The…
27
votes
3 answers

Where is __dso_handle defined?

I have an unresolved symbol error when trying to compile my program which complains that it cannot find __dso_handle. Which library is this function usually defined in? Does the following result from nm on libstdc++.so.6 mean it contains that? I…
revit
  • 361
  • 1
  • 3
  • 10
27
votes
2 answers

Why is -L needed when -rpath is used?

I find that the -L flag must be given when using -rpath. For instance: gcc -o test test.o -L. -lmylib -Wl,-rpath=. Why is the -L flag needed? What information more than the information from the h-files are needed at compile time? If I remove -L. I…
Fredrik Johansson
  • 1,301
  • 1
  • 13
  • 26