I know that when linking to multiple static libraries or object files, the order matters (dependent libraries should be listed before their dependencies). I want to know if, when creating a library file with ar, this same rule applies and the order within the library matters, or within the same .a file it doesn’t make a difference.
I am packing 200+ object files with a complicated dependency graph, and doing
ar rcs mylib.a objs/*.o
is considerably easier then listing them in the correct order.
I am using gcc, if it makes a difference.
The order within the library used to matter long time ago.
It no longer matters on any UNIX system newer than ~15-20 years. From
man ranlib:Most non-ancient UNIX systems either produce the
__.SYMDEF(which contains above index) automatically while building the archive library, or build it in-memory at link time.