107

I'm using Cmake to try to build a project for Eclipse. When I try running Cmake, I get the following error:

Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.
---- Time Elapsed: 3 secs ----
Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.

I'm completely stumped on what might be causing this. I know that I'm running Cmake in the correct directory and the CMakeCache.txt file is present. Could someone point me in the right direction to solve this?

robhasacamera
  • 2,967
  • 2
  • 28
  • 41

19 Answers19

133

If you are using the CLion, you can use File---"Reload CMake Project".

I meet this problem after using git force pull, and Reload CMake Project solves it.

Flamingo
  • 1,573
  • 1
  • 10
  • 4
35

Remove the CMakeCache.txt and try again. You probably had a bad cmake setup. You may want to go to the build directory (build is a subdir to isolate build from source), and issue the command cmake .. In my case it revealed some thing

cmake ..
CMake Error at CMakeLists.txt:1 (project):
  VERSION not allowed unless CMP0048 is set to NEW

You may find other errors.

Kemin Zhou
  • 6,264
  • 2
  • 48
  • 56
amirkavyan
  • 721
  • 7
  • 10
  • 26
    It was [removing `CMakeCache.txt`](http://unix.stackexchange.com/questions/66480/cmake-error-the-current-directory-is-different-than) that started triggering this error for me. – jozxyqk Mar 06 '17 at 22:32
  • Yes, deleting the file is a double-edged weapon. But if it didn't help, something is wrong anyway. E.g. some recursive deps refuse to be configured in-source (I guess, because I have this kind of problem right now...). – Tomasz Gandor Aug 01 '19 at 12:04
  • that's annoying. After trying this three times, then reading your answer, then trying again, it worked. – J-Cake Oct 25 '20 at 11:58
  • Wow, indeed. `rm CMakeCache.txt` and re-doing `cmake --build .` does work now. An additional collection of cmake's sorcery – daparic May 17 '23 at 17:49
26

I have faced the same problem and solved it using the terminal.

  1. Delete the cached/configurations files as we will get them again.
  2. To configure the project run cmake .
  3. Build the project using cmake --build .
Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
13

run cmake --configure . it should generate required files.

rakesh.sahu
  • 465
  • 8
  • 18
  • 6
    I get `cmake --configure .`
    `CMake Error: Unknown argument --configure` `CMake Error: Run 'cmake --help' for all supported options.`
    – Veronica Jun 24 '22 at 01:14
  • Not sure about this. May be issue due to some special character. I often get it when copying '-' from cross platforms. – rakesh.sahu Jun 27 '22 at 09:37
  • may be platform specific, i'm running CentOS 8.5. --help does not list --configure as an option. what got me further was running `cmake .` from the other answer – Brian W Aug 23 '22 at 16:12
11

I ran into this recently using JetBrains CLion and the above instructions were helpful but not directly, I was able to reload the project using the "cog" drop down in the CMake tab:

enter image description here

Nick
  • 1,834
  • 20
  • 32
Reuben Peter-Paul
  • 1,550
  • 3
  • 15
  • 25
8

I got this error on Windows WSL with ubuntu

~/tmp/cmake$ cmake --build ./build
Error: could not load cache

I was able to fix the above error by running the following cmds in order:

% cmake -S . -B ./build 
% cmake --build ./build

The above solution was derived from this post.

atluutran
  • 81
  • 1
  • 4
6

If you are absolutely positive that you are running the build command from the binary directory, this error probably means that you have had an issue during the configuration/generation step that you should have ran before trying the build. You can try to configure again to check (cmake your-build-dir)

I would advise running the Gui and trying to load the cache to see if you get a more explicit error (although I doubt it).

Another possibility would be to try to create a new clean build directory and take it from there.

chaami
  • 1,306
  • 1
  • 9
  • 10
5

In your example Eclipse must run something like

cmake --build folder_name --target all

and I opt that the *folder_name* is bad in this case. You probably messed something up in Eclipse.

Adam
  • 316
  • 2
  • 11
3

For me it helps to select CMake tab (next to Run, TODO) in CLion. Then click the Reload CMakeProject button.

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
2

If you are using Visual Studio 2019, close Visual Studio, delete .vs and out folders then rebuild your project.

Behrouz.M
  • 3,445
  • 6
  • 37
  • 64
1

For vscode users:

  1. re-configure the project: CTRL + SHIFT + P: "CMake: Configure"
  2. re-build the project: CTRL + SHIFT + P: "CMake: Build"
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
doofx
  • 71
  • 7
0

I removed the .cxx and other ide-generated files to the recycle.bin, except app.iml. Then I restarted Android Studio, and eventually it worked fine.

KYHSGeekCode
  • 1,068
  • 2
  • 12
  • 30
0

The solution that worked for me using VisualStudio 2017 was choosing: CMake --> Cache --> Generate (from the top menu)

0

Apart from the already given answers, it might be due to the wrong commands or in wrong order.

To be precise, for me, it was due to

cmake -B build -G Ninja
cmake --build .

The "cmake --build ." command will throw the Could Not Load Cache error.

The problem is the build directory is given as '.' which doesn't have the cache or whatever files cmake generates, so correct command was 'cmake --build build'... and fixed !

There maybe trillion other ways but my solution was this.

For eg, it happened with the repo -> https://github.com/adi-g15/worldlinesim, though may show the same for other repos too.

AdityaG15
  • 290
  • 3
  • 12
0

For Ubuntu users, provide the source code open-pose path in the CMake-GUI.

P.S I had this issue and my path was not set there.

HKay
  • 355
  • 3
  • 7
0

Most probably the issue is you have not wrote the correct name of the Visual Studio version you have installed during the build file preparation:

cmake .. -G "Visual Studio 16 2019" (note if you have VS 2016 you should change in in there)

Sakeador
  • 59
  • 1
  • 3
0

I deleted content inside CMakeFiles directory and also deleted CMakeCache.txt and it worked for me.

rm -rf CMakeFiles/*
rm CMakeCache.txt

It started working after this two steps.

Vishal
  • 516
  • 5
  • 9
-3

The most realistic answer and personal experienced answer is

  1. If you are using Clion and building files with IDE
  2. And getting the error Cmake Error: could not load cache
  3. Because you have accidentally deleted the cache file (like me: permanently and cant get back) or there is other problems or other problems

Then do this:

Run -> Clean

Run -> Build

And your project will be working all fine

Community
  • 1
  • 1
-3
  1. cmake -B ./build(dest dir)
  2. cmake --build ./build(
vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 29 '22 at 15:37