0

I'm trying to set up CMake on Visual Studio code on my computer. I haven't coded outside of work for about a year, and I'm running into problems just setting it up. I've installed the latest version of VS Code, G++ (compiler), mingw, and CMake, including any needed extensions, but I'm still running into this upon using the VSCode "Build" button via CMake Tools:

[main] Building folder: cmakeQuickStart [proc] Executing command: C:\msys64\mingw64\bin\gcc.exe -v [proc] The command: ninja --version failed with error: Error: spawn ninja ENOENT [proc] The command: ninja-build --version failed with error: Error: spawn ninja-build ENOENT [proc] The command: make --version failed with error: Error: spawn make ENOENT [main] 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. Error: No usable generator found. [rollbar] Unhandled exception: Unhandled Promise rejection: build Error: Build failed: Unable to configure the project {}

This is on a HelloWorld project, and my others. I don't know where to go, I've tried dang near everything. Help!

I've tried reinstalling all my components as mentioned above, and starting a new project with the recommended Quick Start on CMake Tools. This error still shows. I've added mingw to my environment variables; I keep seeing that I should add cmake to it as wel, but I'm not sure how.

  • No idea, but my strategy would be to break this down. First try building with g++ alone, does that work? If not there's your problem. Then try building with CMake alone, does that work? Again if not fix that problem, Finally try building with VSCode. You have a complex chain of command, VSCode -> CMake -> g++, it's about breaking that down and finding out where the problem is. – john Apr 16 '23 at 05:44
  • The alternative is to try something simpler. You don't say why you chose the VSCode, CMake, MinGW route. But you have to admit there are a lot of moving parts which must all integrate. An alternative is to download a true IDE like Visual Studio. Only one thing to learn instead of three. – john Apr 16 '23 at 05:47
  • ... have you installed any buildsystem that has a [supported CMake generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html)? Ex. Ninja, Make, Visual Studio? if you haven't, what buildsystem would you want? – starball Apr 16 '23 at 06:00
  • @user I've installed CMake, and I just installed Ninja. I looked and my CMake generator was set to null, but I'm working out what should be there. As far as which buildsystem I'd like, make has worked well in the past. – Ben Comer Apr 16 '23 at 06:43
  • @john Tempted to go with installing VS 2019 on its own (I have to get another license but shouldn't be bad). Will try that if troubleshooting proves fruitless. – Ben Comer Apr 16 '23 at 06:44

1 Answers1

-1
  1. "No usable generator found" indicates that CMake can't determine the generator to use for building the project -- specify the generator -- add this to settings.json (replace "MinGW Makefiles" with the generator that you are using -- "g++.exe" + "gcc.exe" with path to your compilers)
"CMakeTools.generator": "MinGW Makefiles",
"CMakeTools.configureSettings": {
    "CMAKE_CXX_COMPILER": "g++.exe",
    "CMAKE_C_COMPILER": "gcc.exe"
}
  1. "Error: spawn ninja ENOENT" show that CMake Tools can't find the Ninja build system -- install Ninja (add path to Ninja executable to system's PATH environment variable)
mingw-get install ninja
  1. how to add CMake to environment variables
  • start menu > environment variables > Edit the system environment variables > Environment Variables
  • under System variables -- Path > Edit > New > add path to the CMake executable directory > OK on all windows to save changes

once you fix all these issues, try building your project again.

Lemonina
  • 712
  • 2
  • 14
  • why do they need to add CMake's bin folder to their `PATH`? How could they even get to this error message they have if they need to do that?? Who says they _want_ Ninja? What if they want some other buildsystem? While Ninja is a good first choice, the question does not have enough info to write such an answer as you have written yet. – starball Apr 16 '23 at 05:58
  • i agree adding CMake bin to PATH is not necessary for it to work, but it can make it easier to use CMake from command line or other build systems that rely on CMake and OP mentioned that they don't know how to add it at the end of the question -- about the build system, the error message mentioned Ninja, that's why I suggested it as a potential solution -- I agree that they should choose one that fits their requirements – Lemonina Apr 16 '23 at 06:23
  • Trying this now – Ben Comer Apr 16 '23 at 06:29
  • also, where are you getting those VS Code setting names from? prefix looks wrong. – starball Apr 16 '23 at 06:32
  • Not sure what you mean by "Replace MinGW Makefiles with the generator you are using..." would this be g++? Or the path to my CMake? Sorry, I've never been great at this kind of thing – Ben Comer Apr 16 '23 at 06:41
  • I meant replace the generator name "MinGW Makefiles" with the appropriate generator name for your build system -- eg. if you want to use the default Makefiles generator that comes with CMake(replace "MinGW Makefiles" with "Unix Makefiles") If you want to use the Ninja build system(replace "MinGW Makefiles" with "Ninja") – Lemonina Apr 16 '23 at 06:44