Hi Carmelo,
>> 1) main calls bar. bar is defined in libfoo_alias:bar.o
>>
>> 2) bar calls foo_alias. foo_alias is weakly defined in
>> libfoo_alias:foo.o, but there are no strong definitions provided
>> elsewhere, so the weak definition is used. Hence libfoo_alias:foo.o is
>> included in the link which brings with it a strong definition of the
>> "foo" symbol.
>>
> I tried also having foo_alias() a strong alias: does it make any changes?
No. (Or at least it should not).
>> 3) main calls other. other is defined in libfoo.a:foo.o.
>> libfoo.a:foo.o also defines "foo", hence there is now a duplicate
>> definition.
>>
> Ok, thanks for your detailed explanation.. what I don't understand if why
> if libfoo_alias:bar calls foo instead of the alias, having always to strong
> definitions of foo(), the link works fine.
> Could you explain the path in this case?
Are you sure ? I tried it and I still got the error message.
Here is what I did:
1. Edit bar.c to be:
int foo_alias();
int foo();
int bar() {
//return foo_alias();
return foo();
}
2. Rebuild the library:
% ar crv libfoo_alias.a foo_alias.o bar.o
3. Relink the executable:
% gcc -static -L. main.c -lfoo_alias -lfoo
./libfoo.a(foo.o): In function `foo':
foo.c:(.text+0x0): multiple definition of `foo'
./libfoo_alias.a(foo_alias.o):foo_alias.c:(.text+0x0): first defined here
Can you show me what you did please ?