At compile time, the compiler exports each global character to assembler as strong or weak, and assembler implicitly encodes this information in the character table of the moved object file. Functions and initialized global variables receive strong characters. Uninitialized global variables receive weak characters.
Given this concept of strong and weak characters, Unix-linkers use the following rules for working with repeatedly defined characters:
Rule 1: Several strong characters are not allowed.
Rule 2:. If you have a strong character and several weak characters, select a strong character.
Rule 3: If there are several weak characters, select any of the weak characters.
Your code, A1.c as follows:
int i=0;
A2.c as follows:
int i=0;
In accordance with Rule 1, this is not permitted.
For more information: http://www.geeksforgeeks.org/how-linkers-resolve-multiply-defined-global-symbols/
source share