Use# Pragma weakIn name format, the Command makes name a weak symbol. When the link program does not find the symbolic definition of name, no error message is displayed, and multiple weakly defined error messages of the symbol are not displayed. The linked program only executes the first definition encountered.
If another compilation unit has a strong definition of a function or variable, the name is linked to it. If there is no strong definition of name, the value of the link program symbol is 0.
Example1
Compilation unit A cu1.c
<Stdio. h> weak foo * = & (ptr =
Compilation Unit B cu2.c
Foo =;
Compile unit A only:Gcc cu1.c &./a. outTo execute the if statement.
Compile two units:Gcc cu1.c cu2.c &./a. outTo execute the else statement.
Example2
Cu3.c
<Stdio. h> foo (weak foo (foo! =
CompileGcc cu3.c &./a. out, Prompting that foo is not defined.
Example3
Compilation unit A cu4.c
<Stdio. h> foo (foo1 (weak foo = foo1
Compilation Unit B cu5.c
<Stdio. h> foo (
Compile unit A only:Gcc cu4.c &./a. outRun foo1.
Compile two units:Gcc cu4.c cu5.c &./a. outRun foo.