Shridhar Daithankar <[EMAIL PROTECTED]> writes: > On Tuesday 05 Apr 2005 1:17 am, Ian Lance Taylor wrote: > > Shridhar Daithankar <[EMAIL PROTECTED]> writes: > > > gcc -I. -c main.c test1.c test2.c > > > gcc -shared -o libtest1.so test1.o > > > gcc -shared -o libtest2.so test2.o > > > gcc -o test -L. -ltest1 main.o > > > > > > $ ./compile.sh > > > ./libtest1.so: undefined reference to `func4' > > > collect2: ld returned 1 exit status > > > > func4 is defined in libtest2.so. You aren't linking against > > libtest2.so. This is expected behaviour. Why would you expect > > something different? > > The main.c does not have any reference to func4. main.c uses just func1 which > is available in libtest1.so and does not use any function in libtest2.so. So > libtest2.so should not be required at all.
The linker doesn't know that func1 does not need func4. The linker only sees the defined reference in test1.so to func4. You can control this behaviour using the --unresolved-symbols option. See the documentation. > On HP-UX, the build is organized such that each directory produces an archive > library. Some of the directories produce binaries and I have the link command > line that is known to work on HP-UX. > However specifying same dependent libraries produce aforementioned errors on > linux. The linux build is using shared libraries. If the linker could figure > the minimum required dependencies, it will be a great help to me here. If the build worked using archive libraries on HP-UX, why not use archive libraries on Linux? Shared libraries are similar, but different. The easy way to use shared libraries in a similar fashion would be to use --as-needed and link against every shared library. Or to link all the objects together into a single shared library. Ian _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-binutils