#675 Order of objects in ld arguments leads to unresolved symbols

OTHER
closed
Danny Smith
binutils (105)
wont-fix
Known_Feature
2013-01-23
2004-11-08
chudo
No

The order that arguments are passed to g++ in the
linking phase (and therefor I assume to ld) can lead to
unresolved symbol errors that otherwise should not occur.

This bug was found using minGW, executed through MSYS
1.0 on windows XP pro.

gcc version:3.2.3
ld version:2.13.90

Example:

Using the following entry for the linking phase in a
makefile:

foo.exe: $(OBJS)
$(C++) $(LIBDIRS) $(LIBS) $(OBJS) -o $@

gives unresolved symbol errors for every symbol in the
libraries specified in $(LIBS)

while:

foo.exe: $(OBJS)
$(C++) $(OBJS) $(LIBDIRS) $(LIBS) -o $@

compiles properly.

However on a linux machine both examples compile
properly. Therefore I assume this is a minGW specific bug.

Discussion

  • Danny Smith
    Danny Smith
    2004-11-08

    • status: open --> closed
     
  • Danny Smith
    Danny Smith
    2004-11-08

    • status: closed --> closed-wont-fix
     
  • Danny Smith
    Danny Smith
    2004-11-08

    Logged In: YES
    user_id=11494

    Sorry this is the way ld works with archives (and on windows,
    you link to shared libraries using a static archive)

    Have a look through ld.info for --start-group, --end-group for
    a way to get around this, but note that it will slow down
    linking.

    Danny

     
  • Earnie Boyd
    Earnie Boyd
    2004-11-08

    Logged In: YES
    user_id=15438

    I.E.: It is common knowledge that command line order when
    linking libraries is important. You must follow the objects
    with its dependencies. You cannot put the dependencies
    before the objects that depend on them. So if you have
    libfoo.a, libbar.a and libbaz.a where libfoo.a depends on
    libbar.z and libbaz.a depends on libfoo.a you need to
    structure your command line like so:

    gcc -o foo.exe -L. -lfoo -lbar -lbaz -lfoo

    Earnie

     
  • Earnie Boyd
    Earnie Boyd
    2013-01-22

    • labels: ld --> binutils
    • status: closed-wont-fix --> closed
    • resolution: --> wont-fix
    • category: --> Known_bugs
    • milestone: Known_bugs --> OTHER
     
  • Earnie Boyd
    Earnie Boyd
    2013-01-23

    • category: Known_bugs --> Known_Feature