I’m looking at the output of nm -C
0804a86a W ForkMessageHandler::ForkMessageHandler()
0804a86a W ForkMessageHandler::ForkMessageHandler()
0804a6fa T ForkMessageHandler::~ForkMessageHandler()
0804a698 T ForkMessageHandler::~ForkMessageHandler()
0804a698 T ForkMessageHandler::~ForkMessageHandler()
0804a800 W MultiMessageHandler::MultiMessageHandler()
0804a800 W MultiMessageHandler::MultiMessageHandler()
0804a84c W MultiMessageHandler::~MultiMessageHandler()
0804a81c W MultiMessageHandler::~MultiMessageHandler()
0804a81c W MultiMessageHandler::~MultiMessageHandler()
Why does g++ generate many similar symbols, and what’s the purpose of weak symbols ?
Edit: this is from the final executable, not a .o file. ForkMessageHandler is defined in a .cpp file, noone includes a header for it – but several includes headers for its base class.
Those are the default constructors and automatically generated destructors.
They will be generated as weak symbols in every compilation unit that includes the class definition to guarantee that there is at least one available.
The reason they are weak is to avoid conflicts in the linking process since the class definition will be present in every object file including the header file it’s defined.