2018-05-17 16:09 GMT+08:00 Jonathan Wakely <jwakely.gcc@xxxxxxxxx>: > On 17 May 2018 at 08:48, tong chen wrote: >> yeah, It works if places -lintl -lz to the end of the cmd. >> I think It will work with --start-group/--end-group, but It doesn't . > > I think the group will cause the linker to loop over those libraries > in the group, but only at the specified position in the argument list. > > If there are no unresolved references at that point, the linker will > stop looping over the group and continue to other arguments. After > processing the other arguments there are more unresolved references, > but it's too late for libint and libz to help, because they've already > been processed. Thanks for your reply, but is this true? There is some text from <Using ld, the GNU Linker> book: The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. According to this, is the grouped archives will be searched repeatedly while processing every archives on the command line, even they appears later?? > > You always need to list libraries *after* anything that depends on them. -- ------------- Tom Chen