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
36
votes
2 answers

In Xcode project target build settings, What is Mach-O Type?

After getting tired of numerous Match-O linker error, I want to know that this thing means. Instead of trial and error solution, I would like to know the concept behind these things. Specifically I want to know the difference between…
Max
  • 3,371
  • 2
  • 29
  • 30
35
votes
3 answers

When should I write the keyword 'static' before a non-member function?

I've recently seen a bit on SO about the static keyword before a function and I'm wondering how to use it properly. 1) When should I write the keyword static before a non-member function? 2) Is it dangerous to define a static non-member function in…
xcrypt
  • 3,276
  • 5
  • 39
  • 63
35
votes
5 answers

How can I find the full file path given a library name like libfoo.so.1?

Without implementing a linker or using ldd, how can I find the full path to a library? Is there a standard library available for that on Linux? (POSIX maybe?) Using ldd and grep on a file that is knowingly using libGL.so.1, it looks like: $ ldd…
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
34
votes
4 answers

libz.dylib versus libz.1.2.3.dylib versus libz.1.2.5.dylib

I asked this in a comment but this seems like an issue that deserves its own question. I have a project that's shared between three different installations of XCode and two different installations of the iOS SDK. At the moment unifying the…
Hyperbole
  • 3,917
  • 4
  • 35
  • 54
34
votes
4 answers

Calling a function from another file in the same directory in C

I'm learning C, but i have a long experience with higher level programming languages like Java. I was reading about header files so i was playing around with them, however I noticed that I could call a function from another file without #including…
MohamedEzz
  • 2,830
  • 3
  • 20
  • 26
34
votes
5 answers

Linking.canOpenURL returning false when targeting android 30 sdk on React Native

Recently switched our build targets to android 30 to add support for Android 11, now directions and call for phone are not working. The documentation mentions deep linking natively and or the use of an npm package. Would this be done natively? Or is…
Before The Empire
  • 463
  • 1
  • 5
  • 15
34
votes
3 answers

Linking with multiple versions of a library

I have an application that statically links with version X of a library, libfoo, from thirdparty vendor, VENDOR1. It also links with a dynamic (shared) library, libbar, from a different thirdparty vendor, VENDOR2, that statically links version Y of…
YerBlues
  • 541
  • 1
  • 4
  • 7
34
votes
3 answers

What does the Kernel Virtual Memory of each process contain?

When say 3 programs (executables) are loaded into memory the layout might look something like this: alt text http://img97.imageshack.us/img97/3460/processesm.jpg I've following questions: Is the concept of Virtual Memory limited to user processes?…
claws
  • 52,236
  • 58
  • 146
  • 195
34
votes
5 answers

What is the difference between LD_LIBRARY_PATH and -L at link time?

I'm having problems with LD_LIBRARY_PATH at link time (this question has nothing to do with run time). The link line looks like this when I run make (this is a Linux system using g++ version 4.1.x): g++ a.o b.o c.o -o myapp \ -L/long/path/to/libs/…
Dan
  • 5,929
  • 6
  • 42
  • 52
34
votes
2 answers

GCC how to add before the default linker search path by default? LIBRARY_PATH not working

I'm trying to figure out how to set some environment variable which would make g++ to link to correct versions of the libraries. I have some old boost libraries in /usr/lib64 (linking against these will fail) and new libraries in /v/users/regel/lib.…
Regel
  • 607
  • 1
  • 6
  • 11
34
votes
2 answers

Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?

I'm working through an LLVM Tutorial, but I'm having trouble compiling. I've written a minimal example that reproduces the issue: #include "llvm/Module.h" #include "llvm/LLVMContext.h" int main(int argc, char **argv) { llvm::Module *module =…
Matthew
  • 28,056
  • 26
  • 104
  • 170
33
votes
3 answers

Linking a shared library against a static library: must the static library be compiled differently than if an application were linking it?

At least on Linux and Solaris, static libraries are really just a bunch of compiled .o's tossed into one big file. When compiling a static library, usually the -fpic flag is ommited, so the generated code is position dependent. Now say my static…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
33
votes
1 answer

undefined reference to symbol even when nm indicates that this symbol is present in the shared library

What could be wrong here? I have the following simple class: #include "libmnl/libmnl.h" int main() { struct mnl_socket *a = mnl_socket_open(12); } And after running a simple gcc compile (gcc -lmnl main.c) I get the following…
user389238
  • 1,656
  • 3
  • 19
  • 40
32
votes
5 answers

Is there a downside to using -Bsymbolic-functions?

I recently discovered the linker option "-Bsymbolic-functions" in GNU ld: -Bsymbolic When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a…
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
32
votes
7 answers

Undefined reference to operator new

I'm trying to build a simple unit test executable, using cpputest. I've built the cpputest framework into a static library, and am now trying to link that into an executable. However, I'm tied into a fairly complicated Makefile setup, because of…
mbyrne215
  • 2,304
  • 4
  • 21
  • 16