Bug 6938 - ld: failure depending on order of -l libs
Summary: ld: failure depending on order of -l libs
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-02 20:08 UTC by Dmitry Karasik
Modified: 2008-10-03 08:45 UTC (History)
1 user (show)

See Also:
Host:
Target: mingw/cygwin
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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!