Sorry for my bad english.
During GCC compilation, if main.o depends on liba.so, and liba.so depends on libb.so
Then you should link liba.so first and then libb.so. Conversely, an error will occur
The reasons I learned are:
The compiler will traverse all .o, .so modules in sequence, and put them into the list U if they encounter undefined symbols
In the process of sequentially traversing all .o, .so modules, the symbols in the .o, .so are used to interpret the symbols in list U
At the end of traversal, if there are still undefined symbols in U, an undefined symbol error is reported
So if liba.so and libb.so depend on each other, in theory i need to link them like this:
-la -lb -la
However, the actual operation shows that liba.so does not need to be linked twice
Why?
Is the link principle I learned wrong, or did the compiler optimize it