I am building an Xcode static library project, where I have a class defined as:
class New
{
public:
New() {
// Do something
};
static New fNew;
};
__attribute__((used)) New New::fNew;
The static global fNew should not be dead-code stripped by the linker as it has been force declared as ((used)). But I cannot see the constructor getting called for New. Any idea why this is happening?
EDIT: Expectedly, when I add a dummy function to return a pointer to fNew
void* getDummyReference()
{
return (void*)&New::fNew;
}
and call the function from another file in the same static library project, I do not observe the issue any longer and the constructor is called as expected.
Why would the static global be stripped even with atribute((used))?
nm
dump of the object file shows the global object fNew as present, yet the breakpoint doesn't hit in the constructor. – AbhinavChoudhury May 13 '15 at 11:36