From c7960385bec6bee443f459f7b1905e007d4ec993 Mon Sep 17 00:00:00 2001 From: Saran Tunyasuvunakool Date: Fri, 28 Oct 2022 08:41:05 -0700 Subject: [PATCH] Declare DllMain as `extern "C"`. Fixes #550. PiperOrigin-RevId: 484540205 Change-Id: I3915f65f1ae6ab3a93118b9d747b5c09d9abe872 --- include/mujoco/mjplugin.h | 24 ++++++++++++++++-------- unity/Runtime/Bindings/MujocoBindings.cs | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/mujoco/mjplugin.h b/include/mujoco/mjplugin.h index 1ce1b5e5..eccf9d22 100644 --- a/include/mujoco/mjplugin.h +++ b/include/mujoco/mjplugin.h @@ -72,15 +72,23 @@ typedef struct mjpPlugin_ mjpPlugin; #define mjDLLMAIN DllMain #endif +#if !defined(mjEXTERNC) +#if defined(__cplusplus) +#define mjEXTERNC extern "C" +#else +#define mjEXTERNC +#endif // defined(__cplusplus) +#endif // !defined(mjEXTERNC) + // NOLINTBEGIN(runtime/int) -#define mjPLUGIN_DYNAMIC_LIBRARY_INIT \ - static void _mjplugin_dllmain(void); \ - static int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \ - if (reason == 1) { \ - _mjplugin_dllmain(); \ - } \ - return 1; \ - } \ +#define mjPLUGIN_DYNAMIC_LIBRARY_INIT \ + static void _mjplugin_dllmain(void); \ + mjEXTERNC int __stdcall mjDLLMAIN(void* hinst, unsigned long reason, void* reserved) { \ + if (reason == 1) { \ + _mjplugin_dllmain(); \ + } \ + return 1; \ + } \ static void _mjplugin_dllmain(void) // NOLINTEND(runtime/int) diff --git a/unity/Runtime/Bindings/MujocoBindings.cs b/unity/Runtime/Bindings/MujocoBindings.cs index 47b8c204..940e6624 100644 --- a/unity/Runtime/Bindings/MujocoBindings.cs +++ b/unity/Runtime/Bindings/MujocoBindings.cs @@ -50,6 +50,7 @@ public const int mjNREF = 2; public const int mjNIMP = 5; public const int mjNSOLVER = 1000; public const bool THIRD_PARTY_MUJOCO_INCLUDE_MJPLUGIN_H_ = true; +public const bool mjEXTERNC = true; public const bool THIRD_PARTY_MUJOCO_MJRENDER_H_ = true; public const int mjNAUX = 10; public const int mjMAXTEXTURE = 1000;