@@ -182,39 +182,17 @@ struct mjSDF_ {
182182};
183183typedef struct mjSDF_ mjSDF ;
184184
185- #if defined(__has_attribute )
186-
187- #if __has_attribute (constructor )
188- #define mjPLUGIN_LIB_INIT __attribute__((constructor)) static void _mjplugin_init(void)
189- #endif // __has_attribute(constructor)
190-
185+ #if defined(__has_attribute ) && __has_attribute (constructor )
186+ #define mjPLUGIN_LIB_INIT \
187+ static void _mjplugin_init(void) __attribute__((constructor)); \
188+ static void _mjplugin_init(void)
191189#elif defined(_MSC_VER )
192-
193- #ifndef mjDLLMAIN
194- #define mjDLLMAIN DllMain
195- #endif
196-
197- #if !defined(mjEXTERNC )
198- #if defined(__cplusplus )
199- #define mjEXTERNC extern "C"
200- #else
201- #define mjEXTERNC
202- #endif // defined(__cplusplus)
203- #endif // !defined(mjEXTERNC)
204-
205- // NOLINTBEGIN(runtime/int)
206- #define mjPLUGIN_LIB_INIT \
207- static void _mjplugin_dllmain(void); \
208- mjEXTERNC int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \
209- if (reason == 1) { \
210- _mjplugin_dllmain(); \
211- } \
212- return 1; \
213- } \
214- static void _mjplugin_dllmain(void)
215- // NOLINTEND(runtime/int)
216-
217- #endif // defined(_MSC_VER)
190+ #pragma section(".CRT$XCU", read)
191+ #define mjPLUGIN_LIB_INIT \
192+ static void _mjplugin_init(void); \
193+ __pragma(warning(suppress: 4189)) __declspec(allocate(".CRT$XCU")) static void (*_mjplugin_init_ptr)(void) = _mjplugin_init; \
194+ static void _mjplugin_init(void)
195+ #endif
218196
219197// function pointer type for mj_loadAllPluginLibraries callback
220198typedef void (* mjfPluginLibraryLoadCallback )(const char * filename , int first , int count );
0 commit comments