fix Windows native build portability - #4
Open
terbin wants to merge 1 commit into
Open
Conversation
- CMakeLists: use CMAKE_POSITION_INDEPENDENT_CODE instead of a raw -fPIC flag, which is unsupported on the windows-msvc target - CMakeLists: normalize the output arch name so Windows produces PlaceViewer-x86_64.dll (CMAKE_SYSTEM_PROCESSOR is AMD64 there), matching what the Java loader looks for - jni_native_region3d: guard glibc-only malloc_trim() behind __GLIBC__
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two changes so the native (JNI) shared library builds on Windows, with no effect on the Linux build.
Changes
cpp/PlaceViewer/CMakeLists.txt: replaceset(CMAKE_CXX_FLAGS "-fPIC")withset(CMAKE_POSITION_INDEPENDENT_CODE ON). A raw-fPICis invalid on thewindows-msvctarget (andclang-scan-deps, used for C++20 module scanning, promotes it from a warning to a hard error). ThePOSITION_INDEPENDENT_CODEproperty is the portable, compiler-abstracted equivalent: CMake emits-fPICfor the static dependencies on Linux and nothing on Windows. Set before theFetchContentcalls, so it propagates to the fetched static targets. It's also cleaner than the raw flag, which overwroteCMAKE_CXX_FLAGSand only covered C++ (not C) sources.cpp/PlaceViewer/CMakeLists.txt: normalize the output library arch name to what the Java loader (PlaceViewerLibrary.java) expects.CMAKE_SYSTEM_PROCESSORisAMD64on Windows, which producedPlaceViewer-AMD64.dll, but the loader normalizesos.archand looks upPlaceViewer-x86_64.dll(exact match), so the DLL built fine yet would fail to load at runtime. MapAMD64tox86_64(andARM64toaarch64) so the name matches on every platform.cpp/PlaceViewer/src/viewer/jni/jni_native_region3d.cpp:malloc_trimis a glibc-only function. Guard it behind#if defined(__GLIBC__)so it stays active on glibc and compiles to a no-op on Windows/macOS/musl.Verification
PlaceViewer-x86_64.dll(now matches the Java loader's expected name; the DLL statically bundles Boost/zlib/OpenSSL, so at load time it needs only the MSVC runtime + Windows UCRT).libPlaceViewer-x86_64.so. Confirmed viacompile_commands.jsonthat the fetched static dependencies still compile with-fPICand link into the shared object (a successful static-into-shared link on x86-64 is itself proof of PIC). Themalloc_trimsymbol is present in the.so, confirming the glibc branch compiles in.PlaceViewer native libraries have been successfully loaded), registry initialization runs, and the server reaches ready and shuts down cleanly, with noUnsatisfiedLinkError, missing-DLL, or exception.Runtime note (Windows)
The DLL links the MSVC C++ runtime dynamically, so it needs the process's
msvcp140.dllto be ≥ 14.40 (VS 2022 17.10, wherestd::mutex's ABI changed). It still loads fine against an older one, but then null-derefs instd::mutex::lockon the first region load. A JVM that bundles an oldermsvcp140.dllin itsbin/is loaded ahead of the system one, which is how this bites. Launch with a JDK whose bundled runtime is ≥14.40, or, for a fully self-contained DLL, statically link the MSVC runtime (CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded), which would require the vcpkg dependencies rebuilt with thex64-windows-statictriplet. Left as a follow-up; not part of this PR.Dependencies & merge order
This is the umbrella PR of a coordinated Windows/g++ portability set. Because PlaceViewer fetches pinned tags of
zvcrandmc-cpp, a full Windows build needs, in order:2b2tplace/zvcr, companion PR: fix builds under MSVC and g++ zvcr#62b2tplace/mc-cpp, companion PR: fix Windows/MSVC build portability mc-cpp#1GIT_TAGs incpp/PlaceViewer/CMakeLists.txtThis change is safe and independent on its own and does not regress the Linux build; it simply isn't sufficient for a full Windows build until 1-3 are done.