C++ Programming Guide

#pragma weak

#pragma weak function-name1 [= function-name2]

Use weak to define a weak global symbol. This pragma is used mainly in source files for building libraries. The linker does not warn you if it cannot resolve a weak symbol.

The following directive defines bar to be a weak symbol. No error messages are generated if the linker cannot find a definition for a function named bar.


#pragma weak bar

The following directive instructs the linker to resolves any references to bar to bar if it is defined anywhere in the program, and to foo otherwise.


#pragma weak bar = foo

You must declare a function before you use it in a weak pragma. For example:


extern void bar(int);
extern void _bar(int);
#pragma weak _bar=bar

The effects of using #pragma weak are:

See the Solaris Linker and Libraries Guide for more information.


Note -

The names in the pragma must be the names a seen by the linker, which means the "mangled" name if the function has C++ linkage.