CMake Error: The current CMakeCache.txt directory is different...

2023-05-16

零、问题描述
开始学ROS时,需要编译别人的功能包,常常把别人的工作空间拿过来使用,但编译时会出现各种错误,如下的目录问题:
CMake Error: The current CMakeCache.txt directory /home/vistar/desktop/catkin_ws/build/CMakeCache.txt is different than the directory /home/vistar/桌面/catkin_ws/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt

CMake Error: The source “/home/vistar/desktop/catkin_ws/src/CMakeLists.txt” does not match the source “/home/vistar/桌面/catkin_ws/src/CMakeLists.txt” used to generate cache. Re-run cmake with a different source directory.
Invoking “cmake” failed.

一、问题分析

  1. 错误提示翻译一下就是你现在的CMakeCache.txt 文件路径和编译文件记录的CMakeCache.txt 路径不一样。
    (编译时,编译器会根据记录寻找CMakeCache.txt 文件)
    第二个错误也是因为原有记录和现在的路径不一致,不过是CMakeLists.txt文件。
    我以前修改过Ubuntu的目录名,中文改英文,可以看到上面两个路径,一个中文一个英文,就是这个原因导致的。
  2. 在开始创建工作空间时,CMakeCache.txt 和 CMakeLists.txt 本来是不存在的,经过一次catkin_make编译才出现的,把现有的删掉,再编译一次。

二、解决办法

  1. 错误一:将…/build/CMakeCache.txt删掉,重新编译
  2. 错误二:将…/src/CMakeLists.txt删掉,重新编译

最省事的方法:直接将 /build 和 /devel 目录删掉,重新编译 (感谢 如约—————而至weixin_43216765 的提醒,2022-08-28)

三、总结
自己试出来的方法,也许可以通过修改某个文件来解决,如果你有更好的办法,希望可以在下面留言,谢谢你的分享。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CMake Error: The current CMakeCache.txt directory is different... 的相关文章

随机推荐