19

Moved from gcc 4.5 to gcc 4.6, and now it does not link against libraries that are not used at compile time (i.e. if no symbols are imported from them).

However the purpose of those libraries is that they execute static constructors and thus make themselves available to the app at runtime (register their symbols).

Is there a way to force gcc to link with all libraries listed via -l?

queen3
  • 15,333
  • 8
  • 64
  • 119
  • 1
    Probably a change in `as-needed` option. Try preceding your `-l` flags in `-Wl,-no-as-needed` (can't remember the exact syntax and can't access a compiler right now) – Mat Jul 24 '12 at 12:50

1 Answers1

20

It looks like you need either -Wl,--no-as-needed to totally disable it. Or, --no-as-needed -lfoo --as-needed to disable "as-needed" just for libfoo.

Source: https://lists.ubuntu.com/archives/ubuntu-devel/2010-November/031991.html

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Doesn't seem to help, now also trying with --copy-dt-needed-entries. Maybe need to recompile the sources files, not just relink? – queen3 Jul 24 '12 at 13:20
  • This is exactly what I needed and solved an annoying Undefined Symbols issue for me. – amicitas Apr 07 '23 at 20:28