Bug 6938

Summary: ld: failure depending on order of -l libs
Product: binutils Reporter: Dmitry Karasik <dmitry>
Component: ldAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: bug-binutils
Priority: P2    
Version: 2.18   
Target Milestone: ---   
Host: Target: mingw/cygwin
Build: Last reconfirmed:

Description Dmitry Karasik 2008-10-02 20:08:27 UTC
When linking a dll file with ld, where -la and -llib libraries used, order of
-la and -llib matters if these libraries are in .a and .lib formats, respectively. 
The link below[1] points to the setup that can be used to reproduce this
problem. Namely, passing "-la -llib" produces error 

./lib.lib(lib.obj):lib.c:(.text+0x4): undefined reference to `_wlib'

whereas passing "-llib -la" succeeds. There, wlib is exported by lib.lib, and
used by liba.a .

[1] http://karasik.eu.org/misc/ld-bug.tar
Comment 1 Brian Dessent 2008-10-02 22:26:17 UTC
Subject: Re:  New: ld: failure depending on order of -l libs

What is the bug?  The order is significant by design.
Comment 2 Dmitry Karasik 2008-10-03 05:11:56 UTC
Uhm. I didn't know that it is significant by design. Well if it is, then I guess
there's no bug and you may as well close the ticket. However, may I ask for
links for further reading? I can't find anything relevant myself. Thanks!
Comment 3 Brian Dessent 2008-10-03 08:37:06 UTC
Subject: Re:  ld: failure depending on order of -l libs

There is a brief explanation in the manual in the section describing
--start-group/--end-group.  This behavior is not unique to GNU ld, I'm
pretty sure if you went back to the original SysV/BSD linker you'd find
the same algorithm.
Comment 4 Dmitry Karasik 2008-10-03 08:45:08 UTC
That's what I needed, thanks!