Let's say we are the main executable named "my_app" and it uses many other libraries: 3 libraries are connected statically, and the other 3 are dynamically linked
we say We get libsa (such as Static A) which depend on Libseb, and libSC which depends on libSB:
libSA -> LibSB - & gt; BBSC
and three dynamic libraries: libDA - & gt; LibDB - & gt; LibDC
( Libda
is original, libDC is
highest)
in which order should it be linked? Is the original one first or last?
G ++ ... -G GLLSA Libsb Libseb-LDA-LDB -LDC -O My_Pay
seems like the right order, but what Is it? What if there is a stable one or another dependence on the other side of the library?
Fixed issues, it really does not matter, because you do not actually link to static libraries Do - everything you pack into one archive of one object files in one archive. You have to compile your object files, and you can immediately create static library.
The status of dynamic libraries is more complex, there are two aspects:
-
A shared library works the same as the stable library (shared segment) Except if they exist), which means, you can do the same - as soon as your object files are, just link to your shared library, that means the symbol of example from libda will be seen undefined in libDB
-
You share objects You can specify a library to link to the command line while linking. It has the same effect as 1, but marks libDB according to the requirement of libda.
The difference is that if you use it in the past, you must specify the three libraries (-LDA, -LDB, -LDC) when on the command line Executable link If you use later, you only specify LDC and this link will automatically pull others on time. Note that the timing of the link runs before your program (which means that you can get different versions of symbols from different libraries too).
All this applies to Unix; Windows DLL works in a very different way.
Edit after the clarification of the question:
ld
quote from the information book.
The linker will search only one collection at a place where it is specified on the command line. If the archive defines a symbol that was undefined in an object that appeared before the archive on the command line, the linker would contain the appropriate file from the archive, however, the object appearing on the command line would include an undefined symbol linker There will be no reason to search the archive from.
`- ('
This type of archive search is a standard for Unix Linker. However, if you are using` ld' on Ax, note that this AX
It means:
Any static library or object that relies on other libraries should be placed first by the command line If the stable library rely on circulars on each other, you can make the depression
< / Div>- ( -lDA - LDB-LDA
) libraries on the command line option, or the command line. The order of dynamic libraries does not matter.