Dynamic linking is a system which allows libraries to remain separate from programs until loaded, contrast static linking.
Questions tagged [dynamic-linking]
1607 questions
53
votes
3 answers
Linking two shared libraries with some of the same symbols
I link with two different shared libraries. Both libraries define some symbols that share a name but have different implementations. I can't make each library use its own implementation over the other.
For example, both libraries define a global…

drewag
- 93,393
- 28
- 139
- 128
50
votes
5 answers
Overriding 'malloc' using the LD_PRELOAD mechanism
I'm trying to write a simple shared library that would log malloc calls to stderr (a sort of 'mtrace' if you will).
However, this is not working.
Here's what I do:
/* mtrace.c */
#include
#include
static void*…

Dany Zatuchna
- 1,015
- 1
- 10
- 13
45
votes
3 answers
use RPATH but not RUNPATH?
This page says about order for library search in ld.so:
Unless loading object has RUNPATH:
RPATH of the loading object,
then the RPATH of its loader (unless it has a RUNPATH), ...,
until the end of the chain, which is either the…

zaharpopov
- 16,882
- 23
- 75
- 93
42
votes
2 answers
CMake and order dependent linking of shared libraries
I have a few small components that I am building as shared libraries for my main application. Lets use an example of liba and libb. Each is built within their own subdirectory as follows:
add_library(liba SHARED a.cpp)
Then, in the root project…

dusktreader
- 3,845
- 7
- 30
- 40
41
votes
2 answers
Why does the PLT exist in addition to the GOT, instead of just using the GOT?
I understand that in a typical ELF binary, functions get called through the Procedure Linkage Table (PLT). The PLT entry for a function usually contains a jump to a Global Offset Table (GOT) entry. This entry will first reference some code to load…

F30
- 1,036
- 1
- 10
- 21
39
votes
3 answers
Is a statically linked executable faster than a dynamically linked executable?
Since the dynamically linked libraries have to be resolved at run-time, are statically linked executables faster than dynamically linked executables?

Hungary Coder
- 409
- 1
- 4
- 4
38
votes
9 answers
dlopen from memory?
I'm looking for a way to load generated object code directly from memory.
I understand that if I write it to a file, I can call dlopen to dynamically load its symbols and link them. However, this seems a bit of a roundabout way, considering that it…

Jeremy Salwen
- 8,061
- 5
- 50
- 73
38
votes
1 answer
Static and Dynamic/Shared Linking with MinGW
I want to start with a simple linking usage to explain my problem. Lets assume that there is a library z which could be compiled to shared library libz.dll(D:/libs/z/shared/libz.dll) or to static library libz.a (D:/libs/z/static/libz.a).
Let I want…

Yuki
- 3,857
- 5
- 25
- 43
37
votes
2 answers
why do we need the shared library during compile time
Why we need the presence of the shared library during the compile time of my executable? My reasoning is that since shared library is not included into my executable and is loaded during the runtime, it is not supposed to be needed during compile…

Gab是好人
- 1,976
- 1
- 25
- 39
34
votes
3 answers
How can LD_LIBRARY_PATH be changed within CMake?
I have a local shared library which is not in $LD_LIBRARY_PATH.
I want to run my executable, but since it cannot find the shared library in the system folders, it outputs "error while loading shared libraries".
A possible fix for this is to export a…

Daniel Saad
- 385
- 1
- 3
- 9
33
votes
2 answers
C++ -fvisibility=hidden -fvisibility-inlines-hidden
I have a question about the C++ visibility attribute. I have read http://gcc.gnu.org/wiki/Visibility and yet I dont quite understand how it works.
I want use the visibility to be hidden on some of my shared libraries I have. I believe this means…

nixgadget
- 6,983
- 16
- 70
- 103
32
votes
9 answers
C/C++ How Does Dynamic Linking Work On Different Platforms?
How does dynamic linking work generally?
On Windows (LoadLibrary), you need a .dll to call at runtime, but at link time, you need to provide a corresponding .lib file or the program won't link... What does the .lib file contain? A description of…

Charlie
- 4,197
- 5
- 42
- 59
32
votes
4 answers
What are possible causes of "failed to map segment from shared object: operation not permitted", and how to debug?
I have two executables, both cross compiled to run in Android. I have put both on the device in the same directory. I have put all the shared libraries that they are dependent on in the same directory, including ld-linux.so.3. I run the…

corbin
- 1,446
- 2
- 27
- 40
31
votes
6 answers
Linking GLEW with CMake
How can you link GLEW to a project with CMake?
We've been trying to link GLEW to our project using CMake for at least 3 hours without any success so any help is accepted.
I'm using the FindGLEW.cmake which comes with CMake…

Lord Zsolt
- 6,492
- 9
- 46
- 76
31
votes
1 answer
What's going on in __libc_start_main?
I'm really trying to understand the steps from high level code -> executable.. but am having some difficulties.
I've written an empty int main() {} C file and am trying to decipher the disassembly via objdump -d. Here's what's going on:
in _start,…

gone
- 2,587
- 6
- 25
- 32