From d0ed8b36cc5a4b2b5eef8f33763acb88b90381f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Wed, 15 May 2024 20:06:03 +0200 Subject: [PATCH 1/2] FindKLU.cmake: Avoid detecting MSVC libraries when targeting MinGW (#476) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For MinGW, setting the library prefix is not necessary and setting the library suffix to d.lib is incorrect. The static library suffix is .a for MinGW. Prepending those values to the list of library prefixes and suffixes might not actually cause an issue if no libraries are found that match those patterns. But slight ABI differences between MSVC and MinGW could lead to unexpected behavior when mixing binaries of both targets. This was already discussed in https://github.com/LLNL/sundials/pull/407#discussion_r1481939567. But apparently that change got lost in one of the rebases in that PR. --------- Signed-off-by: Markus Mützel --- cmake/tpl/FindKLU.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/tpl/FindKLU.cmake b/cmake/tpl/FindKLU.cmake index 96b9d7343b..a3d817d037 100644 --- a/cmake/tpl/FindKLU.cmake +++ b/cmake/tpl/FindKLU.cmake @@ -46,7 +46,7 @@ if (NOT (KLU_INCLUDE_DIR OR KLU_LIBRARY_DIR OR KLU_LIBRARY)) endif() # Set library prefixes for Windows -if(WIN32) +if(MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) set(CMAKE_FIND_LIBRARY_PREFIXES lib ${CMAKE_FIND_LIBRARY_PREFIXES}) set(CMAKE_FIND_LIBRARY_SUFFIXES d.lib ${CMAKE_FIND_LIBRARY_SUFFIXES}) elseif(APPLE) @@ -95,7 +95,7 @@ endif () if (NOT SUITESPARSECONFIG_LIBRARY) set(SUITESPARSECONFIG_LIBRARY_NAME suitesparseconfig) # NOTE: no prefix for this library on windows - if(WIN32 AND NOT MSYS) + if(MSVC OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")) set(CMAKE_FIND_LIBRARY_PREFIXES "") endif() find_library( SUITESPARSECONFIG_LIBRARY ${SUITESPARSECONFIG_LIBRARY_NAME} ${KLU_LIBRARY_DIR} NO_DEFAULT_PATH) From e8b7acd0663dcb0864644607003873c12cf94187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=BCtzel?= Date: Wed, 15 May 2024 23:48:27 +0200 Subject: [PATCH 2/2] Use `int64_t` for `KLU_INDEXTYPE` if `SUNDIALS_INT64_T` is true. (#477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `long int` is 32 bits wide on systems that use an LLP64 data model (e.g., Windows). Use a type for which the C standard guarantees that it is 64-bit instead (i.e., `int64_t`). See the error in CI for PR #432. Signed-off-by: Markus Mützel Co-authored-by: Cody Balos --- CHANGELOG.md | 3 +++ doc/shared/RecentChanges.rst | 3 +++ src/sunlinsol/klu/sunlinsol_klu.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59ffc7a35d..40706c1649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,9 @@ Fixed a CMake bug that caused an MPI linking error for our C++ examples in some Fixed a bug in `ARKodeSPRKTable_Create` where the coefficient arrays where not allocated. +Fix bug on LLP64 platforms (like Windows 64-bit) where `KLU_INDEXTYPE` could be +32 bits wide even if `SUNDIALS_INT64_T` is defined. + ## Changes to SUNDIALS in release v7.0.0 ### Major Feature diff --git a/doc/shared/RecentChanges.rst b/doc/shared/RecentChanges.rst index a6eef5064e..4f1e6dbe92 100644 --- a/doc/shared/RecentChanges.rst +++ b/doc/shared/RecentChanges.rst @@ -65,3 +65,6 @@ Fixed a CMake bug that caused an MPI linking error for our C++ examples in some Fixed a bug in :c:func:`ARKodeSPRKTable_Create` where the coefficient arrays where not allocated. + +Fix bug on LLP64 platforms (like Windows 64-bit) where ``KLU_INDEXTYPE`` could be +32 bits wide even if ``SUNDIALS_INT64_T`` is defined. diff --git a/src/sunlinsol/klu/sunlinsol_klu.c b/src/sunlinsol/klu/sunlinsol_klu.c index cbdaa54135..568dc1d549 100644 --- a/src/sunlinsol/klu/sunlinsol_klu.c +++ b/src/sunlinsol/klu/sunlinsol_klu.c @@ -16,6 +16,7 @@ * the SUNLINSOL package. * -----------------------------------------------------------------*/ +#include #include #include #include @@ -49,7 +50,7 @@ */ #if defined(SUNDIALS_INT64_T) -#define KLU_INDEXTYPE long int +#define KLU_INDEXTYPE int64_t #else #define KLU_INDEXTYPE int #endif