The order of object files in a static library

I know that when linking to multiple static libraries or object files, order matters (dependent libraries must be specified before their dependencies). I want to know if when creating a library file with ar the same rule applies and the order in the library matters or in the same .a file, it does not matter.
I collect 200+ object files with a complex dependency graph and do

 ar rcs mylib.a objs/*.o 

much easier than listing them in the correct order.

I use gcc if that matters.

+4
source share
1 answer

The order in the library used to resolve the issue a long time ago.

This does not matter for any UNIX system, newer ~ 15-20 years. From man ranlib :

  An archive with such an index speeds up linking to the library and allows routines in the library to call each other without regard to their placement in the archive. 

Most non-ancient UNIX systems either create __.SYMDEF (which contains the index above) automatically when creating the archive library, or build it in memory during communication.

+6
source

Source: https://habr.com/ru/post/1388530/


All Articles