In object-oriented languages (C++) you can execute code before main() by using a global object or a class static object and have their constructors run the code
main()
There are portable ways of specifying functions that can be executed "after" main is executed.
atexit()
at_quick_exit()
Further, follow this link and about various types of initialization in C++ - that may be useful for you to execute code before main() is called.