Why can't I configure a CMake target with CLion (Nothing to run on)?

Viewed 13130

I'm struggling to run a program with CLion on Windows 10. It was working fine a couple weeks ago and the only thing I could think of that might have broken things is installing git.

As you can see from the below picture, the run button is greyed out and the run configuration says "Nothing to run on", which I'm guessing refers to the target.

enter image description here

What I've done So Far

I tried going through the steps outlined in the accepted answer of this question: How do I set up CLion to compile and run?

  • I installed MinGW in C:\MinGW
  • Added C:\MinGWand C:\MinGW\bin to the path
  • I've configured paths to my Environment, CMake, Make, C Compiler, and C++ Compiler

enter image description here

  • I've set my target & executable, but the only target I can choose is 'All targets'.

enter image description here

If I run this program through 'Run->Run...' and select the 'Wahum' run configuration, I get the following output in my Event Log:

Error running 'Wahum': Cannot run 'Wahum' on '<default>'
10 Answers

What worked for me is selecting the top CMakeList.txt file, right-clicking on it and selecting Load CMake Project from the context menu.

enter image description here

I have CLion 2020.2.1 and there is no import project option in the file menu.

my working solution:

File > Invalidate caches and restart

It seems to me that there is a valid CMakeLists.txt in your directory, however CLion is not finding it. This is probably happening because you have deleted/misplaced some files from your .idea directory. I'm not sure this is the optimal solution, but what has helped me in this situation is to re-import the project.

File-> Import Project... and select directory with your project.

You are going to get a warning message Directory '{dir}' already contains CMake project, go ahead and choose Open existing project, select Open in this window and after that CLion should recognize your CMakeList.txt again and run cmake (did for me at least).

My setup was a little different, but I managed to make it work doing this:

  • Deleted the ".idea" file for the project.
  • Deleted all cmake files & folders for the project (cmake-build_xyz, CMakeLists, .clion.source.upload.marker, etc)
  • Deleted other cmake files found in parent directories (which I knew were not supposed to be used)
  • Created a new project "from the files" (of the project initial project)
  • Deleted any CMake Profile (Settings-> Build, Execution, Deployment->CMake)
  • Created a new CMake Profile.
  • Added the code back in the CMakeLists.txt
  • Reloaded the CMake.

A difference in my setup was that I was building on a remote computer (Linux) over SSH. So I had some entries in the "Deployment" section (Settings-> Build, Execution, Deployment-> Deployment). Therefore, I did the same thing on the target and the host to make sure that any conflicting while would not be synced on top of the "other file".

While looking for a solution, I did try to setup a dummy project using Microsoft Toolchains without any success.

In CLion 2020.1.3 I have found that switching targets and switching back seems to avoid a bug that causes "Nothing to run on" to appear next to what I presume is a valid target.

I had the same error message using CLion with Googletest when running a specific test: "Cannot run xyz on ". The above hints did not work for me.

What worked was to rename the test, run it, then rename back. Solved.

Try to add a new configuration using the "Custom Build Application" template instead of a "CMake Application", and select the custom target you created earlier as the Target.

I delete the .cache cmake-build-debug/

and backup the CMakeLists.txt and then delete it.

and then add a new CMakeLists.txt for the project and copy the backup comment to it.

and now run the code. it work! Yeah

For me, "File" -> "Reload CMake Project" did the trick.

If you want to make new CMakeLists.txt, do the following.

Go to Tools --> CMake --> Unload CMake Project.

Then open any source file. It will suggest you create or load CMake file, just click on create a new file and select the source files that you want to include.

Related