Error :No CMAKE_Fortran_COMPILER could be found. Visual studio 2017 enterprise instead of MinGW

  • 9 months ago
Comment

ChatGPT
1 / 1

The error message "No CMAKE_Fortran_COMPILER could be found" usually indicates that CMake couldn't locate a valid Fortran compiler during the configuration process. Since you're using Visual Studio 2017 Enterprise instead of MinGW, you need to set up CMake to use the appropriate compiler.

Here's how you can configure CMake to use the Visual Studio 2017 compiler:

  1. Open Command Prompt:
    Open the "x64 Native Tools Command Prompt for VS 2017" or the "x86 Native Tools Command Prompt for VS 2017" from the Start menu. This command prompt sets up the environment variables for Visual Studio tools.

  2. Navigate to Source Directory:
    Use the cd command to navigate to the root directory of your project (where your CMakeLists.txt is located).

  3. Run CMake with Generator:
    Use the cmake command to configure your project with the appropriate generator for Visual Studio. You need to specify the generator using the -G flag.

    For 64-bit build with Visual Studio 2017:

    bash
    cmake -G "Visual Studio 15 2017 Win64" .

    For 32-bit build with Visual Studio 2017:

    bash
    cmake -G "Visual Studio 15 2017" .

    Replace . with the path to your source directory if you're not already in it.

  4. Generate Project Files:
    After running the above command, CMake will generate the necessary project files for Visual Studio.

  5. Open Project in Visual Studio:
    Navigate to the project folder and open the .sln file that was generated by CMake. This will open the project in Visual Studio.

  6. Build the Project:
    Build the project using Visual Studio. Make sure to set up the configuration (Debug/Release) and platform (x64/x86) correctly.

By following these steps, you'll be configuring and building your project using the Visual Studio compiler instead of MinGW, and the error related to the Fortran compiler should be resolved.