Skip to content

Commit 698a36b

Browse files
al42andacmnpv
authored andcommitted
Fix linker error on Windows with Intel oneAPI
Don't assume how to link `libm`, rely on CMake for it. Fixes #5240
1 parent e0180bc commit 698a36b

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -522,8 +522,8 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "XL")
522522
endif()
523523

524524
include(CheckLibraryExists)
525-
find_library(HAVE_LIBM m)
526-
mark_as_advanced(HAVE_LIBM)
525+
find_library(LIBM_LIBRARY m)
526+
mark_as_advanced(LIBM_LIBRARY)
527527
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
528528
check_library_exists(m feenableexcept "" HAVE_FEENABLEEXCEPT)
529529
check_library_exists(m fedisableexcept "" HAVE_FEDISABLEEXCEPT)
@@ -893,8 +893,8 @@ if(HAVE_TIME_H AND HAVE_UNISTD_H AND HAVE_CLOCK_GETTIME)
893893
endif()
894894

895895
# Math and thread libraries must often come after all others when linking...
896-
if (HAVE_LIBM)
897-
list(APPEND GMX_PUBLIC_LIBRARIES m)
896+
if (LIBM_LIBRARY)
897+
list(APPEND GMX_PUBLIC_LIBRARIES ${LIBM_LIBRARY})
898898
endif()
899899

900900
option(GMX_NACL "Configure for Native Client builds" OFF)

cmake/FindFFTW.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ if (${FFTW}_FOUND)
8787
#The user could specify trash in ${FFTW}_LIBRARY, so test if we can link it
8888
include(CheckLibraryExists)
8989
include(gmxOptionUtilities)
90-
if (HAVE_LIBM)
90+
if (LIBM_LIBRARY)
9191
#adding MATH_LIBRARIES here to allow static libs, this does not harm us as we are anyway using it
92-
set(CMAKE_REQUIRED_LIBRARIES m)
92+
set(CMAKE_REQUIRED_LIBRARIES ${LIBM_LIBRARY})
9393
endif ()
9494
gmx_check_if_changed(FFTW_LIBRARY_CHANGED ${FFTW}_LIBRARIES)
9595
if (FFTW_LIBRARY_CHANGED)

docs/release-notes/2024/2024.5.rst

+9
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,14 @@ Handle trajectory reading error in gmx tcaf
3030
Fixes that affect portability
3131
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3232

33+
Fix linking error on Windows with Intel oneAPI
34+
""""""""""""""""""""""""""""""""""""""""""""""
35+
36+
Fix ``LINK : fatal error LNK1181: cannot open input file ‘m.lib’``
37+
error encountered when using ``icx`` compiler on Windows by using
38+
dynamically-detected name for the ``m`` library.
39+
40+
:issue:`5240`
41+
3342
Miscellaneous
3443
^^^^^^^^^^^^^

0 commit comments

Comments
 (0)