I would go with option 1 (although option 2 works, I would not recommend it since then, someone who links exe should remember all the necessary transitive libraries).
However, this tip is only for creating the so file, as you do above. so files (shared objects) are โsmartโ libraries similar to executable files, except that they donโt have a core library. so files can reference other libraries (for example, executables), and when the executable refers to the so file, it automatically recursively includes the dependencies of the so file.
Therefore, the so file you create must be associated with all its dependencies.
The dumb library, such as file a (static library), is a different story; then you need to follow all the links in the executable file (option 2).
I recommend using the ldd tool to examine the dependencies of the executable and so file to find out how it works.
For an example in the real world why option 1 is better, try ldd /usr/lib/libpng.so . Note that libpng is associated with libz. If this were not the case, anyone who has ever contacted libpng would also have to reference libz. Be that as it may, you can reference libpng without even knowing that libz is involved.
source share