Skip to content

fix Windows/MSVC build portability - #1

Open
terbin wants to merge 1 commit into
2b2tplace:mainfrom
terbin:windows-portability
Open

fix Windows/MSVC build portability#1
terbin wants to merge 1 commit into
2b2tplace:mainfrom
terbin:windows-portability

Conversation

@terbin

@terbin terbin commented Jul 13, 2026

Copy link
Copy Markdown

Summary

Three portability fixes so mc_cpp compiles and links under Windows (clang targeting the MSVC ABI, dependencies via vcpkg). Non-Windows behavior is unchanged.

Changes

  • include/mc_cpp/crypto/rsa.cpp: std::filesystem::path::c_str() returns const wchar_t* on Windows, so it doesn't match fopen(const char*, ...). Use _wfopen on Windows and fopen elsewhere; add #include <cstdio>. Using _wfopen with the native wide path also keeps Unicode paths intact; a narrow fopen would route the filename through the lossy ANSI code page (CP_ACP).
  • include/mc_cpp/registry/registries/biomes.cpp: std::clamp(a, b, c) deduces a single type from all three arguments. UINT8_MAX is unsigned char on the MSVC UCRT (but int on glibc), so deduction fails to compile on MSVC. Pin std::clamp<int>(...); a no-op where the arguments were already int.
  • CMakeLists.txt: z/crypto are Unix library names. On Windows, resolve zlib and OpenSSL via find_package(ZLIB) / find_package(OpenSSL) and link the imported targets ZLIB::ZLIB / OpenSSL::Crypto (plus ws2_32). The non-Windows branch keeps the existing link_libraries(z crypto) unchanged.

Verification

Builds and links as part of the PlaceViewer native library on Windows (clang 22 + vcpkg: boost-iostreams, zlib, openssl) and Linux (g++ 13.3). The non-Windows code paths (the #else fopen, the else() link branch) are unchanged from upstream. The resulting library was also run on a live Windows Paper 1.21.4 server, where mc_cpp's registry initialization executed successfully.

Notes / possible follow-up

The imported-target link approach could be made unconditional (it would also modernize the Linux link and drop the discouraged directory-scope link_libraries). This PR intentionally keeps the Linux path byte-identical to avoid touching the currently-working build; happy to make it unconditional if preferred.

Part of a coordinated Windows/g++ portability set

- rsa.cpp: open the key file with _wfopen on Windows, where
  std::filesystem::path::c_str() is const wchar_t*; add <cstdio>
- biomes.cpp: use std::clamp<int> so the arguments share a type
  (UINT8_MAX is unsigned char on the MSVC UCRT but int on glibc,
  which breaks deduction)
- CMakeLists: on Windows, resolve zlib/OpenSSL via find_package
  imported targets instead of the Unix link names z/crypto
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.

1 participant