bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with linking ununsed symbols in a shared library


From: Shridhar Daithankar
Subject: Problem with linking ununsed symbols in a shared library
Date: Mon, 4 Apr 2005 22:18:56 +0530
User-agent: KMail/1.7.2

Hi,

First of all, sorry for posting the sources inline but I don't know if 
attachments are allowed on this list. I am not subscribed, so please CC to 
me.

While porting a project from HP-UX to Linux I ran into this problem where the 
linker asks for all the dependent shared libraries, not only the once that 
are required to satisfy the undefined symbols.

Here is a small test case to reproduce a problem. A common header file test.h, 
defines 4 functions. These functions are implemented in two different 
libraries. An executable depends upon only one of these functions but linker 
asks for implementation of all the functions since the other functions do 
depend upon themselves..

To my understanding, the link should succeed. Is this a bug?

I am using Slackware10.1, binutils version binutils-2.15.92.0.2-i486-2.

Regards,
 Shridhar

P.S.
To reproduce
------------
$ cat test.h
#include <stdio.h>

extern int func1(int a);
extern int func2(int b);

extern int func3(int a);
extern int func4(int b);

$ cat test1.c
#include <test.h>

int func1(int a)
{
 return(a);
}
int func3(int a)
{
 return(func4(a));
}

$ cat test2.c
#include <test.h>

int func2(int a)
{
 return(a);
}
int func4(int a)
{
 return(a);
}

$ cat main.c

#include <test.h>

int main(void)
{
 printf("The Value is %d\n",func1(10));
 return(0);           
 }

$ cat compile.sh
#!/bin/bash

rm -f *.so *.o test

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             
------------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]