As known, when linking target to a series of libraries using gcc, we need to give the compiler (gcc) the correct order of the linked libraries. For example:
Source file a.cpp depends on libb.a, libc.a and libd.a.
Library libb.a depends on libc.a and libd.a.
Therefore, the compiling command should be
g++ a.cpp -o a libb.a libc.a libd.a
Moreover, we cannot reverse the order between b and c or between b and d. Normally, we have to manually figure out the order of all linked libraries. Certainly, there is also some way to bypass this problem. We can add
-Wl,--start-group $(LIBRARIES_YOU_NEED) -Wl,--end-group
so ld can figure out the order by itself. However, I would like to know the order of the linked libraries for myself.
So, given all libraries needed by a source file, are there any automatic ways to sort the libraries so that the dependency between them are correct when they are put in the gcc command line?