Skip to content

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#201

Open
lorisercole wants to merge 9 commits intowavefunction91:masterfrom
lorisercole:fix/msvc-build
Open

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#201
lorisercole wants to merge 9 commits intowavefunction91:masterfrom
lorisercole:fix/msvc-build

Conversation

@lorisercole
Copy link
Copy Markdown
Contributor

  • Fix MSVC native cl.exe build compatibility:
    • __PRETTY_FUNCTION____FUNCSIG__ under _MSC_VER guard
    • __builtin_popcount → C++20 std::popcount (MSVC has no GCC builtins)
    • C99 [restrict] array params → *__restrict pointers in 14 rys files
    • __attribute__((always_inline))FORCE_INLINE macro (__forceinline on MSVC)
    • C99 VLAs → _malloca/_freea in rys_rw.c and rys_xrw.c
    • __attribute__((__aligned__(64)))alignas(64) in 20 integral_*.cxx files
    • __restrict____restrict in integral_1_0.cxx
    • Add missing #include <string> in reduction_driver.hpp
    • Make Molecule::operator== const for C++20 compatibility
  • Fix static HDF5 linking on Windows: patch HighFive's libdeps to use H5_BUILT_AS_STATIC_LIB and link transitive deps (zlib, szip/aec, shlwapi)
  • Fix clang-cl issues:
    • Add missing #include <stdlib.h> in gau2grid_helper.c (implicit exit() declaration)
    • Replace deprecated strdup with _strdup across 7 exception headers
    • Add missing newline at end of file in 4 source files
    • Suppress noisy clang-cl warnings (-Wno-covered-switch-default, -Wno-documentation, etc.)
    • Suppress MSVC cl.exe warnings (/wd4100, /wd4101, /wd4242, /wd5219)
  • Update ExchCXX and IntegratorXX dependency hashes to include their MSVC fixes

Requires:

GauXC was only buildable with GCC, Clang, and clang-cl. This commit fixes all
compilation and linking issues when building with MSVC's native `cl.exe` compiler.

## Compiler compatibility fixes
- `__PRETTY_FUNCTION__` → `__FUNCSIG__` (`exceptions.hpp`):
  MSVC does not support `__PRETTY_FUNCTION__`; use `__FUNCSIG__` under `_MSC_VER` guard.
- `__builtin_popcount` → `std::popcount` (`exx_screening.cxx`):
  MSVC does not provide GCC builtins; use C++20 `<bit>` header instead.
- C99 `[restrict]` array params → `*__restrict` pointers (14 rys files):
  MSVC does not support the C99 array parameter syntax. The `*__restrict` pointer
  form is portable across GCC, Clang, and MSVC.
- `__attribute__((always_inline))` → `FORCE_INLINE` macro (`rys_integral.c`):
  Maps to `__forceinline` on MSVC and `__attribute__((always_inline))` on GCC/Clang.
  Also replaces the GNU statement-expression `MIN` macro with a simple ternary.
- C99 VLAs → `_malloca`/`_freea` (`rys_rw.c`, `rys_xrw.c`):
  MSVC does not support VLAs. Uses `_malloca`/`_freea` (stack with heap fallback)
  under `_MSC_VER` guards.
- `__attribute__((__aligned__(64)))` → `alignas(64)` (20 `integral_*.cxx` files):
  Portable C++11 alignment specifier, works on GCC, Clang, and MSVC.
- `__restrict__` → `__restrict` (`integral_1_0.cxx`):
  `__restrict__` is GCC/Clang-only; `__restrict` is portable across all three compilers.
- Missing `#include <string>` (`reduction_driver.hpp`):
  MSVC does not provide `<string>` transitively through other headers.
- Non-const `operator==` (`molecule.hpp`):
  Made `Molecule::operator==` `const` to fix C++20 ambiguity with synthesized
  reverse candidates on MSVC.

## Static HDF5 linking fixes (`src/external/CMakeLists.txt`)

- HighFive incorrectly propagates `H5_BUILT_AS_DYNAMIC_LIB`:
  CMake's `FindHDF5` module sets this define on Windows when `HDF5_USE_STATIC_LIBRARIES`
  is unset, regardless of whether the library is actually static. HighFive then
  propagates it via its `libdeps` INTERFACE target. The fix patches `libdeps` after
  `FetchContent` to replace `H5_BUILT_AS_DYNAMIC_LIB` with `H5_BUILT_AS_STATIC_LIB`.
- HDF5 transitive static dependencies:
  When linking HDF5 statically on Windows, its dependencies (zlib, szip/aec, shlwapi)
  must be linked explicitly as they are not auto-resolved.
warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup.
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