last day (16 days later) » 

3:58 PM
2
A: Do libraries reported by ldd resolve all undefined references of an input library?

Mike Kinghan Do libraries reported by ldd resolve all undefined references of an input library? No. A shared library may be linked containing undefined references (and this is commonplace). So it may be linked containing undefined references that will not be resolved by any of its (recursive) DSO depende...

 
Now let's suppose we want to create an application that uses function foo from main.c: gcc main.c -lfoo -llibc -o main.exe. We will get an unresolved reference to function bar inside the source foo.c of libfoo.so, right? We have added all the libraries reported by ldd libfoo.so, but we still have unresolved reference inside libfoo.so. So my question is what is the use of ldd and its output?
 
@Alexey The purpose of ldd is to show you the name of each shared library in the recursive linkage of a shared library or dynamically linked program and of the actual file, if any, to which the runtime loader maps that name. It may be you want ask a different question: Why would I ever want to know the dynamic dependencies of a shared library or program, as reported by ldd?
 
My confusion is because of the fact that ldd seems have nothing (or a little) to do with undefined references. What programming tasks require ldd?
 
@Alexey That really is a different question, which I and no doubt others could answer, if you post it. It's one question at a time on SO.
 
Here it is stackoverflow.com/questions/54092584/what-is-the-purpose-of-‌​ldd But not everybody agree that it should be a different post because I've asked "what is the use of ldd at all" here.
 
3:58 PM
@Alexey On reading n.m's answer, I think he covers the usefulness of ldd
 
I hope. Could you please tell me does it make sense to use ldd with a shared library ldd shared_library.so (instead of using ldd with an application ldd application)?
 
That depends on what question you are trying to investigate by running `ldd libfoo.so`.
If e.g. you want to discover its recursive dynamic dependencies, it is the most sensible thing to do. If you want to discover what shared libraries to add to a linkage along with `libfoo.so` to resolve all references in the linkage, it tells you at least some of them, but [`pkg-config`](https://linux.die.net/man/1/pkg-config) is the go-to tool to tell
you the canonical compilation and linkage requirements for the use of a library.
 
Hi! I'm very glad to chat with you! It seems to me that I just don't understand the purpose of this tool. I've thought that it's purpose to show the list of the libraries that we need to add to linkage to resolve undefined references, but it turns out it's not so
Are you there?
 
4:28 PM
You are right. That is not the purpose of `ldd`. There is in principle no algorithmic *right* answer to the question of what files must
be added to a linkage along with `libfoo.so` to resolve all undefined references in
the linkage or even in `libfoo.so` itself. The shared libraries listed by `ldd libfoo.so` are (almost certainly)
files that will resolve *some* undefined references in `libfoo.so` itself. As
far as the remainder are concerned, *any* files that define those symbols will
resolve those references, possibly in a way that provides expected runtime behaviour
 
Well, tell me please what do you mean by "If e.g. you want to discover its recursive dynamic dependencies"
What does dependency mean?
Does it mean an undefined reference?
 
 
2 hours later…
6:25 PM
The dynamic dependencies listed by `ldd libfoo.so` are simply the shared libraries that `libfoo.so` was in fact linked with when it was created. The linker records them as `DT_NEEDED` in `libfoo.so`. The runtime loader will then load them into a process if it loads `libfoo.so`.
The reason for linking them with `libfoo.so` is that they will resolve at least some of the undefined references in `libfoo.so` at runtime, so if they are not `DT_NEEDED` by `libfoo.so` then they will have to be independently `DT_NEEDED` in the linkage of any program with which `libfoo.so` is linked.
 

  last day (16 days later) »