Bug 6853 - --as-needed doesn't work on more than 1 DSO
Summary: --as-needed doesn't work on more than 1 DSO
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.19
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-22 22:02 UTC by H.J. Lu
Modified: 2008-08-22 22:06 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2008-08-22 22:02:30 UTC
[hjl@gnu-6 needed-5]$ cat foo.c
extern void bar ();

void
foo ()
{
  bar ();
}
[hjl@gnu-6 needed-5]$ cat bar.c
void
bar ()
{
}
[hjl@gnu-6 needed-5]$ cat main.c
extern void foo ();

int
main ()
{
  foo ();
  return 0;
}
[hjl@gnu-6 needed-5]$ make foo
gcc  -O -g   -c -o main.o main.c
gcc  -O -g -fPIC   -c -o bar.o bar.c
gcc  -shared -o libbar.so bar.o
gcc  -O -g -fPIC   -c -o foo.o foo.c
gcc  -shared -o libfoo.so foo.o
gcc  -o foo main.o -Wl,--as-needed libfoo.so libbar.so -Wl,--no-as-needed
-Wl,-rpath,.
libfoo.so: undefined reference to `bar'
collect2: ld returned 1 exit status
make: *** [foo] Error 1
[hjl@gnu-6 needed-5]$
Comment 1 H.J. Lu 2008-08-22 22:06:18 UTC
I guess it is OK since libfoo.so should be linked with libbar.so.