static link problems with alias

Carmelo Amoroso carmelo73@gmail.com
Thu Jan 4 16:44:00 GMT 2007


Hi All,
I've encountered a problem doing a static link due to duplicated symbols error.
I reproduced the scenario with simple test cases as follows (see
attached sources)

I have the following dummy functions:
- int foo();
- foo_alias() as weak alias of foo()
- int bar(); (thats call foo_alias())
all archived into libfoo_alias.a

and the following ones:

int foo();
int other();
archied into libfoo.a

and the main.c calling bar() and other().

When I compile the main with the following command:

gcc -static -L. main.c -lfoo_alias -lfoo I get the following error:

./libfoo.a(foo.o)(.text+0x0): In function `foo':
: multiple definition of `foo'
./libfoo_alias.a(foo_alias.o)(.text+0x0): first defined here
collect2: ld returned 1 exit status

If I modify the bar() function calling foo() instead of the alias, it
successfully linked.

Where I'm going wrong? is the failing path working correctly?

Regards,
Carmelo

P.S.
My env as follows:
Red Hat Enterprise Linux AS 4
gcc version 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
GNU ld version 2.15.92.0.2 20040927

same behaviour with gcc 4.1.1 and ld 2.17.50
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bar.c
Type: text/x-csrc
Size: 64 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20070104/d75d0689/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 56 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20070104/d75d0689/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo_alias.c
Type: text/x-csrc
Size: 229 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20070104/d75d0689/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 42 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20070104/d75d0689/attachment-0003.bin>


More information about the Binutils mailing list