Skip to content

Improve MinGW compatibility#3090

Open
Ashutosh0x wants to merge 2 commits intogoogle-deepmind:mainfrom
Ashutosh0x:fix/mingw-compatibility-general
Open

Improve MinGW compatibility#3090
Ashutosh0x wants to merge 2 commits intogoogle-deepmind:mainfrom
Ashutosh0x:fix/mingw-compatibility-general

Conversation

@Ashutosh0x
Copy link
Contributor

This Pull Request addresses several build and link issues encountered when compiling MuJoCo with the MinGW-w64 toolchain.

Changes

  • Fix stat redefinition: Added #ifndef stat around the #define stat _stat in user_vfs.cc. MinGW-w64 often defines stat as a macro (e.g., _stat64), causing a conflict with MuJoCo's manual mapping.
  • Support thread-safe localtime: Changed the check in engine_util_errmem.c from #elif _MSC_VER to #elif defined(_WIN32). MinGW-w64 provides the same localtime_s function as MSVC, but it was previously hidden.
  • Fix stack size flag: Updated MujocoLinkOptions.cmake to use -Wl,--stack,size instead of -Wl,/STACK:size when using the GNU compiler on Windows. GNU ld does not recognize the MSVC-style /STACK flag.

These changes combined with PR #3086 (printf format errors) should allow MuJoCo to build out-of-the-box with modern MinGW-w64 environments.

Fixes #3037, #3038, #3040

This commit addresses several build and link issues when using the MinGW-w64 toolchain:

- Fix redefinition of 'stat' in user_vfs.cc by checking if it's already a macro.

- Support thread-safe 'localtime_s' on Windows by using _WIN32 instead of _MSC_VER in engine_util_errmem.c.

- Use the correct --stack flag for GNU ld on Windows in MujocoLinkOptions.cmake.

Fixes google-deepmind#3037, google-deepmind#3038, google-deepmind#3040
@mmossg
Copy link
Collaborator

mmossg commented Feb 11, 2026

Why is this needed when you already have #3083 and #3084?

@Ashutosh0x
Copy link
Contributor Author

Why is this needed when you already have #3083 and #3084?

Thanks for checking!

PR #3083 and #3084 addressed specific Windows/MinGW issues individually, but during testing I found additional build and linking problems that still prevented a clean out-of-the-box MinGW-w64 build.

This PR bundles the remaining fixes (stat macro conflict, localtime_s detection, and GNU ld stack flag) so MuJoCo can compile successfully in a modern MinGW environment end-to-end

@Ashutosh0x
Copy link
Contributor Author

I've removed the redundant linker flag changes, as they are already covered in #3083. This PR now solely focuses on the stats macro and thread-safe localtime fixes.

@mmossg
Copy link
Collaborator

mmossg commented Feb 12, 2026

#3084 has the stats and local time fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiling mujoco with MinGW fails because of thread-safe localtime

2 participants