I am enhancing a tool.
Please note that this tool will be linked to test program, which will have main( ) function, so my tool can’t have main. What this tool has is a number of functions which the test program will use.
Now additionally, i want to add a timer to this tool. The idea is: when the test program is linked to this tool and starts, the timer should automatically start.
If this was C++, i would have created a class with a constructor, so that whenever the class is loaded, the constructor is called first, and i can initialize my timer inside the constructor.
If this was Java, i would have simply created a global static block, and put the timer code inside the static block.
But my tool is purely in C in Linux, so how can i achieve this goal?
Please help me.
This looks like your case also:
How do I get the GCC __attribute__ ((constructor)) to work under OSX?
From GCC docs: