使用ifort的CMake项目失败 “无法编译简单的测试程序”

问题描述

我可以在Linux和Windows中使用gfortran编译项目,而不会出现错误。但是由于某种原因,我必须在Windows中使用ifort.exe作为编译器,但失败了。有人可以帮忙吗? 详细信息如下:

-- Detecting Fortran compiler ABI info  
-- Detecting Fortran compiler ABI info - Failed  
-- Check for working Fortran compiler: D:/Program Files/IVF/compilers_and_libraries_2018.3.210/windows/bin/intel64/ifort.exe  
-- Check for working Fortran compiler: D:/Program Files/IVF/compilers_and_libraries_2018.3.210/windows/bin/intel64/ifort.exe- broken   CMake Error at D:/Program Files/CMake/share/cmake-3.18/Modules/CMakeTestFortranCompiler.cmake:51 (message):   The Fortran compiler

    "D:/Program Files/IVF/compilers_and_libraries_2018.3.210/windows/bin/intel64/ifort.exe"

  is not able to compile a simple test program.  It fails with the following output:

   Change Dir: C:/Users/xxx/build/CMakeFiles/CMakeTmp

   Run Build Command(s):D:/PROGRA~2/MINGW-~1/X86_64~1.0-P/mingw64/bin/mingw32-make.exe cmTC_809ef/fast && mingw32-make.exe[1]: Entering directory  'C:/Users/xxx/build/CMakeFiles/CMakeTmp' 
   D:/PROGRA~2/MINGW-~1/X86_64~1.0-P/mingw64/bin/mingw32-make.exe  -f CMakeFiles\cmTC_809ef.dir\build.make CMakeFiles/cmTC_809ef.dir/build   
   mingw32-make.exe[2]: Entering directory 'C:/Users/xxx/build/CMakeFiles/CMakeTmp'    
   Building Fortran object CMakeFiles/cmTC_809ef.dir/testFortranCompiler.f.obj  
   D:\PROGRA~2\IVF\COMPIL~1.210\windows\bin\intel64\ifort.exe  /nologo /fpp   /W1 /nologo /fpp /libs:dll /threads  /Od /debug:full /dbglibs /FoCMakeFiles\cmTC_809ef.dir\testFortranCompiler.f.obj  /FdCMakeFiles\cmTC_809ef.dir/ -c C:\Users  xxx\build\CMakeFiles\CMakeTmp\testFortranCompiler.f 
   warning #31001: The dll for reading and writing the pdb (for example,mspdb110.dll) Could  not be found on your path. This is usually a configuration error. Compilation will continue using /Z7 instead of /Zi,but expect a similar err r when you link your program. 
   Linking Fortran executable cmTC_809ef.exe    
   "D:\Program  Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\cmTC_809ef.dir\link.txt --verbose=1    
   "D:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_809ef.dir --rc=rc --mt="" --manifests -- xilink /nologo @CMakeFiles\cmTC_809ef.dir\objects1.rsp /out:cmTC_809ef.exe /implib:cmTC_809ef.lib /pdb:C:\Users\xxx\build\CMakeFiles\CMakeTmp\cmTC_809ef.pdb /version:0.0 /machine:x64  /debug /INCREMENTAL:YES /subsystem:console user32.lib    
   RC Pass 1: command "rc /fo CMakeFiles\cmTC_809ef.dir/manifest.res CMakeFiles\cmTC_809ef.dir/manifest.rc" Failed (exit code 0) with the following output:   
   The system cannot find the file specified.mingw32-make.exe[2]: *** [CMakeFiles\cmTC_809ef.dir\build.make:107: cmTC_809ef.exe] Error -1   mingw32- 
   make.exe[2]: Leaving directory 'C:/Users/xxx/build/CMakeFiles/CMakeTmp'          
   mingw32-make.exe[1]: *** [Makefile:140: cmTC_809ef/fast] Error 2    
   mingw32-make.exe[1]: Leaving directory 'C:/Users/xxx/build/CMakeFiles/CMakeTmp'

解决方法

该错误是因为找不到rc.exe。我通过将文件路径添加到PATH变量来解决了这个问题。