先说一下个人使用的环境和建立工程的方式:
环境:ubuntu20.04+cmake+vscode, 建立的是C++工程。
方式:用的是较为简单的方式。建立一个工程目录,下面有一个build目录,一个cpp源文件,CMakeLists.txt文件。如下图所示:

(.vscode文件是配置时自动生成的,有时有,有时没有)
然后编译运行一般是三板斧:

cd build
cmake ..
make
./可执行文件名

在ubuntu下用cmake编译C++工程时,如果改变了工程文件的位置,那么在build文件中运行cmake … 时有可能会出现这样的错误:CMake Error: The current CMakeCache.txt directory /home/.../build/CMakeCache.txt is different than the directory /home/.../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/.../CMakeLists.txt" does not match the source "/home/.../CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
(中间的省略号省略了几层路径)。我这里的情况是新建了一个文件夹(或者称为目录),将原来的C++项目文件都挪到这个文件夹下了。从报错提示可以看到,这是因为当前CMakeCache.txt的路径和它之前被创建的路径不同了。
解决办法很简单:
1.退出build目录:

cd ..

2.删除build目录(要确保build中只存放了编译生成的中间文件)

rm -rf build

3.新建build目录

mkdir build

4.进入build

cd build

5.重新cmake …

cmake ..

这时就不会报错了

Ubuntu下cmake报错:The current CMakeCache.txt directory...is different from...相关推荐

  1. CMake安装时报错:The current CMakeCache.txt directory /home/joes/jiao/01_YHWorker/03_setupbag/cmake-3.19.2

    一.问题描述: CMake Error: The current CMakeCache.txt directory /home/joes/jiao/01_YHWorker/03_setupbag/cm ...

  2. CMake Error: The current CMakeCache.txt directory is different than the other

    CMake Error: The current CMakeCache.txt directory is different than the other - CMake安装报错:CMakeCache ...

  3. 【转】CMake Error: The current CMakeCache.txt directory CMakeCache.txt is different than the directory

    转自:CMake Error: The current CMakeCache.txt directory is different..._万俟淋曦的进击手记-CSDN博客 零.问题描述 开始学ROS时 ...

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

    CMake Error: The current CMakeCache.txt directory is different... 使用 NXP sdk编译时会出现如下错误: CMake Error: ...

  5. 在aarch64-himix100-linux-gcc下cmake报错(The C compiler identification is unknown)

    项目场景: 华为好望角AI摄像头C系列的算法移植过程中,遇到cmake报错 问题描述: gcc: aarch64-himix100-linux-gcc CMakeLists.txt文档: cmake_ ...

  6. ubuntu下Tensorflow 报错: ImportError: No module named 'matplotlib'

    我的问题是: 在使用Jupyter Notebook跑tensorflow程序时,出现报错ImportError: No module named 'matplotlib',然而在spyder(非te ...

  7. Ubuntu下Qt报错 “cannot find -lGL“

    libgl1-mesa-dev是有关OpenGL的库. 原因是不能找到Opengl的库,但是在Ubuntu下能搜索到.创建一个软链接解决此问题. find /usr -name libGL* ln - ...

  8. Ubuntu下Pangolin报错what(): pangolin x11: failed to open x display

    在orangepi板子,Ubuntu16.04上对ORB-SLAM进行运行的过程中,出现以下错误: terminate called after throwing an instance of 'st ...

  9. ubuntu下QT报错缺失libgstreamer解决方案

    转自: http://www.cnblogs.com/gongxijun/p/6722339.html sudo wget http://ftp.ca.debian.org/debian/pool/m ...

最新文章

  1. LeetCode-动态规划基础题-343. 整数拆分
  2. (75)内核APC执行过程,分析 KiDeliverApc 函数
  3. How to change the background color of button in Footer area
  4. [蓝桥杯][2018年第九届真题]小朋友崇拜圈(简单图论)
  5. maven项目,如何导入本地jar包
  6. rails再体验(第一个程序)
  7. Struts2 自定义验证器
  8. lnmp测试php,php ,nginx 搭建负载均衡lnmp,小白测试
  9. abb机器人写字程序实例_abb机器人程序实例
  10. C++中的声明和定义
  11. 开课吧python小课学了有用吗-考研人注意了,停下手头的活,再忙也要看一下这个!...
  12. MacBookpro安装mysql教程_mac安装mysql的两种方法
  13. 逐步揭示makop.mkp勒索病毒中毒防范恢复解密
  14. PCAN监测can总线状态设置
  15. 银河麒麟v10_中国崛起?我对银河麒麟操作系统V10的一点小看法
  16. MyBatisPlus 又搞事情,发布权限神器!
  17. html css 实现文字竖排模拟古籍排版
  18. 前装车载大屏娱乐系统去年增速超六成,德赛西威“霸榜”主机份额
  19. 让我们用 Node.js 写自己的 DDNS 动态域名程序
  20. 新型勒索软件Phobos利用弱安全性***目标

热门文章

  1. java启动依赖包问题_spring boot创建项目包依赖问题的解决
  2. 机试算法讲解: 第11题 贪心之猫鼠大战
  3. 关于java基础练习的趣味小游戏(猜数游戏)
  4. hdu 5411 CRB and Puzzle(矩阵快速幂)
  5. 历来中国功夫vs泰拳战史
  6. 【清风数学建模笔记】第一讲:层次分析法
  7. 异质图神经网络(持续更新ing...)
  8. python网络爬虫与信息提取_北京理工大学_Python网络爬虫与信息提取(一)
  9. 链表反转 递归实现Java
  10. 联想台式机突然黑屏,只有屏幕左上角有短白线闪,断电后重启仍无法开机并有嘀嘀嘀异响