Hello list,
I writting a cross-platform shared library (.dll, .so). I need to initialize some global variables.
As the free pascal doesn't support library events (PROCESS_ATTACH, PROCESS_DETACH), what is the correct to way to do this?
best
ragrds

Mailing lists / fpc-pascal / 2016-04
7 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hello list,
I writting a cross-platform shared library (.dll, .so). I need to initialize some global variables.
As the free pascal doesn't support library events (PROCESS_ATTACH, PROCESS_DETACH), what is the correct to way to do this?
best
ragrds
It does, but it catches them in the system unit; I do not think they are exposed.
Michael.
2016-04-13 15:52 GMT-03:00 Michael Van Canneyt :
So, what is the correct way to initialize global variables? In a normal program i can use unit's initialization section or class constructors. But the documentation is not clear about the the case of shared libraries.
regrds
It does, but it catches them in the system unit; I do not think they are exposed. Michael.
And hence you can just initialise those variables in the initialization section of the library and finalize them (if necessary) in the finalization section of the library.
Jonas
2016-04-13 15:56 GMT-03:00 Jonas Maebe :
Thanks!
Can i use class constructors in shared libraries? Does unit's initialization section and class constructors have the same behaviour in all platforms and the same when compared with a normal program?
regards
Yes and mostly yes. The finalization sections might not be called in the context of the same thread as the initialization sections, because if the thread that does the last unload of the library (if it is dynamically loaded) then it's called in that thread's context. But other then that they behave the same as for normal programs.
Regards,
Sven
2016-04-13 16:48 GMT-03:00 Sven Barth :
Thanks for the clarification!
Regards