ImagingDataCommons / libdicom

C library for reading DICOM files
https://libdicom.readthedocs.io
MIT License
15 stars 7 forks source link

Automatically call `dcm_init()` when built with MSVC #68

Closed bgilbert closed 9 months ago

bgilbert commented 9 months ago

It's awkward that libdicom automatically initializes itself in a thread-safe way, except when compiled on one major compiler for one major platform. While __attribute__((constructor)) doesn't exist on MSVC, equivalent functionality is available.

One approach is to handle DLL_PROCESS_ATTACH in DllMain(), but that doesn't work when statically linked. The more general approach is to put an initializer in a .CRT$XCU section (example), though there are subtleties to prevent the constructor from being GCed during LTO. glib uses this latter mechanism.