Linker and Libraries Guide

Complex Resolutions

Complex resolutions occur when two symbols of the same name are found with differing attributes. In these cases the link-editor selects the most appropriate symbol and generates a warning message indicating the symbol, the attributes that conflict, and the identity of the file from which the symbol definition is taken. For example:


$ cat foo.c
int array[1];

$ cat bar.c
int array[2] = { 1, 2 };

$ cc -dn -r -o temp.o foo.c bar.c
ld: warning: symbol `array' has differing sizes:
         (file foo.o value=0x4; file bar.o value=0x8);
         bar.o definition taken

Here, two files with a definition of the data item array have different size requirements. A similar diagnostic is produced if the symbols' alignment requirements differ. In both of these cases, the diagnostic can be suppressed by using the link-editor's -t option.

Another form of attribute difference is the symbol's type. For example:


$ cat foo.c
bar()
{
         return (0);
}
$ cc -o libfoo.so -G -K pic foo.c
$ cat main.c
int     bar = 1;

main()
{
         return (bar);
}
$ cc -o main main.c -L. -lfoo
ld: warning: symbol `bar' has differing types:
         (file main.o type=OBJT; file ./libfoo.so type=FUNC);
         main.o definition taken

Here the symbol bar() has been defined as both a data item and a function.


Note -

types in this context are the symbol types that can be expressed in ELF. They are not related to the data types as employed by the programming language, except in the crudest fashion.


In cases like this, the relocatable object definition is taken when the resolution occurs between a relocatable object and a shared object, or, the first definition is taken when the resolution occurs between two shared objects. When such resolutions occur between symbols of different bindings (weak or global), a warning is also produced.

Inconsistencies between symbol types are not suppressed by the link-editor's -t option.