For any particular unresolved reference, libraries are searched only once, and only for symbols that are undefined at that point in the search. If you list more than one library on the command line, then the libraries are searched in the order in which they are found on the command line. Place -llibrary options as follows:
Place the -llibrary option after any .f, .for, .F, .f95, or .o files.
If you call functions in libx, and they reference functions in liby, then place -lx before -ly.