Cmake 错误: 无法加载缓存

我正在使用 Cmake 尝试为 Eclipse 构建一个项目。当我尝试运行 Cmake 时,会得到以下错误:

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.

我完全不知道是什么引起的。我知道我正在正确的目录中运行 Cmake,并且 CMakeCache.txt 文件存在。有人能给我指出解决这个问题的正确方向吗?

122790 次浏览

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.

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.

Remove the CMakeCache.txt and try again. You probably had a bad cmake setup.

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

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.

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

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.

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

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

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

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

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.

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.

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 .

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)

  1. cmake -B ./build(dest dir)
  2. cmake --build ./build(

According to this tutorial. You have to navigate to the build directory first:

cmake ../{currentDirectory}

That's all! Now you can use cmake --build . to build your application.

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.