7

while compiling cpp files in vs code in windows 10 PC, after giving "cmake:debug" I get error like this "unable to determine what cmake generator to use.please install or configure a preferred generator or update settings.json, your kit configuration or path variable" how to solve the error

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
anjaly
  • 81
  • 1
  • 1
  • 2
  • Did you install cmake and set it up in your project? – bolov Dec 02 '21 at 11:19
  • I installed cmake and also added it's path to system environment variable. – anjaly Dec 03 '21 at 04:00
  • Any luck with this issue? Were you able to solve the problem? – user541396 Mar 13 '22 at 17:53
  • For correct cmake generation of mingw I use ninja. You should add ninja path to system environment variable or just to copy ninja.exe to bin folder witch you already added or install it with help pacman. – igor Mar 29 '22 at 09:50
  • Use the `Ninja` generator whenever you can. `Ninja` is significantly faster than any of the other options and it's trivial to install and use. – Jesper Juhl Jul 17 '23 at 17:09

2 Answers2

9

Firstly check the system.

  1. Install MINGW https://www.msys2.org/

  2. Install gcc, g++, gdb, and cmake using pacman.

    pacman -S mingw-w64-x86_64-gcc

    pacman -S mingw-w64-x86_64-gdb

    pacman -S mingw-w64-x86_64-cmake

  3. Check installation:

    gcc --version

    g++ --version

    gdb --version

  4. Edit environment variables for your account (PATH)

    C:\msys64\mingw64\bin

For cmake project on Vscode:

  1. Create a cmake project: https://code.visualstudio.com/docs/cpp/cmake-linux#_create-a-cmake-project

  2. Choose the Kit (Toolchain) which was installed before

  3. Set cmake.cmakePath (If you installed with pacman, the path should be same as gcc/g++.

    "cmake.cmakePath": "C:\msys64\mingw64\bin\cmake.exe"

  4. Reset VScode: Ctrl+shift+P and type "CMake:Reset CMake Tools for Extension State"

  5. Configure project: Ctrl+shift+P and type "CMake: Configure". You will see "built" directory and generated files.

gkhanacer
  • 575
  • 7
  • 25
  • 1
    Very good and quick guide. I think it should be in official vscode docs :) – pktiuk Oct 29 '22 at 12:36
  • I found that I also needed to select "let cmake choose which kits to use" after running reset. If you choose the VS Code selected one it still remains broken. – pups Jul 17 '23 at 17:04
6

If you have install cmake, setted up your project and you added it's path, try this Ctrl+shift+P and Type "cmake:reset cmake tools for extension state" and press enter.

At least that works for me.

Luis Díaz
  • 61
  • 1
  • 3