LLVMFlang: Missing support for targeting MSVC ABI on Windows
Hi, I am trying to compile a very simple Fortran program using CMake and LLVM 16.0's flang-new for Windows on Arm and I am seeing the following behaviour.
Using the following Fortran source code
program hello
implicit none
write(*,*) 'Hello world!'
end program hello
and the following CMakeLists.txt
enable_language (Fortran)
project(helloworld Fortran)
add_executable(hello test.f)
with the following command line
cmake -G Ninja -DCMAKE_Fortran_COMPILER=FLANG-NEW -DCMAKE_Fortran_COMPILER_FORCED=1 -DCMAKE_Fortran_FLAGS="-flang-experimental-exec" ..
And it generates this rule
#############################################
# Rule for linking Fortran executable.
rule Fortran_EXECUTABLE_LINKER__hello_
command = cmd.exe /C "$PRE_LINK && C:\PROGRA~1\LLVM\bin\FLANG-~1.EXE $FLAGS $LINK_FLAGS $in -o $TARGET_FILE -Wl,--out-implib,$TARGET_IMPLIB -Wl,--major-image-version,0,--minor-image-version,0 $LINK_PATH $LINK_LIBRARIES && $POST_BUILD"
description = Linking Fortran executable $TARGET_FILE
restat = $RESTAT
Which is an incorret rule. I just noticed that this might be the reason why I need to use CMAKE_Fortran_COMPILER_FORCED because if I don’t I see a similar thing
-- Check for working Fortran compiler: C:/Program Files/LLVM/bin/flang-new.exe - broken
CMake Error at C:/Users/everton/CMake/share/cmake-3.26/Modules/CMakeTestFortranCompiler.cmake:59 (message):
The Fortran compiler
"C:/Program Files/LLVM/bin/flang-new.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/everton/source/repos/OpenBLAS/build3/out/CMakeFiles/CMakeScratch/TryCompile-1so3bv
Run Build Command(s):C:/PROGRA~1/MICROS~1/2022/COMMUN~1/Common7/IDE/COMMON~1/MICROS~1/CMake/Ninja/ninja.exe -v cmTC_5c4f4 && [1/4] cmd.exe /C "C:\PROGRA~1\LLVM\bin\FLANG-~1.EXE -cpp -flang-experimental-exec -E C:\Users\everton\source\repos\OpenBLAS\build3\out\CMakeFiles\CMakeScratch\TryCompile-1so3bv\testFortranCompiler.f > CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f-pp.f && C:\Users\everton\CMake\bin\cmake.exe -E cmake_ninja_depends --tdi=CMakeFiles\cmTC_5c4f4.dir\FortranDependInfo.json --lang=Fortran --pp=CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f-pp.f --dep=CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f-pp.f.d --obj=CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f.obj --ddi=CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f.obj.ddi"
flang-new: warning: argument unused during compilation: '-flang-experimental-exec'
[2/4] C:\Users\everton\CMake\bin\cmake.exe -E cmake_ninja_dyndep --tdi=CMakeFiles\cmTC_5c4f4.dir\FortranDependInfo.json --lang=Fortran --dd=CMakeFiles\cmTC_5c4f4.dir\Fortran.dd @CMakeFiles\cmTC_5c4f4.dir\Fortran.dd.rsp
[3/4] C:\PROGRA~1\LLVM\bin\FLANG-~1.EXE -IC:\Users\everton\source\repos\OpenBLAS\build3\out\CMakeFiles\CMakeScratch\TryCompile-1so3bv -flang-experimental-exec -ffixed-line-length-72 -c CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f-pp.f -o CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f.obj
FLANG-~1: warning: argument unused during compilation: '-flang-experimental-exec'
[4/4] cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\FLANG-~1.EXE -flang-experimental-exec CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f.obj -o cmTC_5c4f4.exe -Wl,--out-implib,libcmTC_5c4f4.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
FAILED: cmTC_5c4f4.exe
cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\FLANG-~1.EXE -flang-experimental-exec CMakeFiles\cmTC_5c4f4.dir\testFortranCompiler.f.obj -o cmTC_5c4f4.exe -Wl,--out-implib,libcmTC_5c4f4.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
lld-link: warning: ignoring unknown argument '--out-implib'
lld-link: warning: ignoring unknown argument '--major-image-version'
lld-link: warning: ignoring unknown argument '--minor-image-version'
lld-link: error: could not open 'libcmTC_5c4f4.dll.a': no such file or directory
lld-link: error: could not open '0': no such file or directory
lld-link: error: could not open '0': no such file or directory
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (enable_language)
My CMake is version 3.26.1 on a SurfaceX machine.