Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-04

Initialization in Shared Libraries

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mazola Winstrol

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

Michael Van Canneyt
to Mazola Winstrol
Mazola Winstrol wrote 7 lines
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?

It does, but it catches them in the system unit; I do not think they are exposed.

Michael.

Mazola Winstrol
to Michael Van Canneyt

2016-04-13 15:52 GMT-03:00 Michael Van Canneyt :

Show quoted text 17 lines
On Wed, 13 Apr 2016, Mazola Winstrol wrote: 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? > It does, but it catches them in the system unit; I do not think they are exposed.

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

Jonas Maebe
to Michael Van Canneyt: It does, but it catches them in the system unit; I do not think they are exposed. Michael.
Michael Van Canneyt wrote 12 lines
On Wed, 13 Apr 2016, Mazola Winstrol wrote: > 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? It does, but it catches them in the system unit; I do not think they are exposed.

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

Mazola Winstrol
to Jonas Maebe

2016-04-13 15:56 GMT-03:00 Jonas Maebe :

Show quoted text 6 lines
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.

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

Sven Barth
to Mazola Winstrol
Mazola Winstrol wrote 14 lines
2016-04-13 15:56 GMT-03:00 Jonas Maebe < >: 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. 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?

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

Mazola Winstrol
to Sven Barth

2016-04-13 16:48 GMT-03:00 Sven Barth :

Show quoted text 8 lines
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.

Thanks for the clarification!

Regards