fortran-lang / stdlib

Fortran Standard Library
https://stdlib.fortran-lang.org
MIT License
1.05k stars 164 forks source link

Cannot build using cmake with gfortran on Windows -- the Fortran compiler identification is unknown #328

Open Beliavsky opened 3 years ago

Beliavsky commented 3 years ago

This is not a stdlib-specific problem, but others may encounter the same obstacle. When I try to build stdlib using cmake on Windows, I get the following problem. How do I tell cmake to use gfortran and specify its location? I see discussion of this problem here but don't see a resolution.

c:\fortran\public_domain\github\stdlib_20210302>gfortran --version GNU Fortran (GCC) 11.0.0 20200927 (experimental) Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

c:\fortran\public_domain\github\stdlib_20210302>cmake -B build -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.21322. -- The Fortran compiler identification is unknown CMake Error at CMakeLists.txt:2 (project): No CMAKE_Fortran_COMPILER could be found.

-- Configuring incomplete, errors occurred! See also "C:/fortran/public_domain/github/stdlib_20210302/build/CMakeFiles/CMakeOutput.log". See also "C:/fortran/public_domain/github/stdlib_20210302/build/CMakeFiles/CMakeError.log".

leonfoks commented 3 years ago

I think add -DCMAKE_Fortran_COMPILER=\<path-to-gfortran> to the cmake command

Beliavsky commented 3 years ago

Thanks @leonfoks . Even when I tell cmake to use gfortran, it tries to use Intel Fortran within Visual Studio for some reason:

c:\fortran\public_domain\github\stdlib_20210302>cmake -B build -DCMAKE_Fortran_COMPILER=c:/equation/bin -- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.21322. -- The Fortran compiler identification is unknown -- Detecting Fortran compiler ABI info -- Detecting Fortran compiler ABI info - failed -- Check for working Fortran compiler: c:/equation/bin -- Check for working Fortran compiler: c:/equation/bin - broken CMake Error at C:/Users/myname/AppData/Roaming/Python/Python36/site-packages/cmake/data/share/cmake-3.18/Modules/CMakeTestFortranCompiler.cmake:51 (message): The Fortran compiler

"c:/equation/bin"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: C:/fortran/public_domain/github/stdlib_20210302/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/devenv.com CMAKE_TRY_COMPILE.sln /build Debug /project cmTC_9872c && 
Microsoft Visual Studio 2017 Version 15.0.28307.423.
Copyright (C) Microsoft Corp. All rights reserved.

The license for Visual Studio has expired.

The evaluation period for this product has ended.

CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:2 (project)

-- Configuring incomplete, errors occurred! See also "C:/fortran/public_domain/github/stdlib_20210302/build/CMakeFiles/CMakeOutput.log". See also "C:/fortran/public_domain/github/stdlib_20210302/build/CMakeFiles/CMakeError.log".

leonfoks commented 3 years ago

I should have said specify the full path to gfortran, not just the path to the containing folder, so add gfortran to the end.

cmake -B build -DCMAKE_Fortran_COMPILER=c:/equation/bin/gfortran

Beliavsky commented 3 years ago

I should have said specify the full path to gfortran, not just the path to the containing folder, so add gfortran to the end.

cmake -B build -DCMAKE_Fortran_COMPILER=c:/equation/bin/gfortran

Thanks, but that's not the problem. The gfortran binary is at c:\equation\bin\gfortran.exe .

leonfoks commented 3 years ago

Yes I see, I get the same thing. Personally i've installed MinGW and then use cmake -G "MinGW Makefiles" and it detects fine.

I did not see the subtle difference between what you tried and what i'm used to, so apologies for that! I tried to get it working without assuming a MinGW install but no dice yet and I get the message you posted.