首页 > 解决方案 > CMake 引用我在 ~/bin 中创建的随机 shell 脚本(即使在我删除它之后)?

问题描述

在 Ubuntu(20.04,Cinnamon 桌面)中,我创建了一个基本的 shell 脚本来从命令行运行具有以下内容的 .desktop 文件:

#!/bin/sh
$(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &

然后运行chmod +x以便能够将其作为命令执行。现在,每当我使用 时cmake --build,它都会包含这个文件的内容——即使在我删除了有问题的脚本完全重新启动之后。这是我最近尝试 cmake 的输出:

alexander@alexander-Inspiron-7559:~/Documents/Code/CPP/SDLProject/bin$ cmake --build .
CMake Error: The current CMakeCache.txt directory /home/alexander/Documents/Code/CPP/SDLProject/bin/CMakeCache.txt is different than the directory /home/alexander/Documents/Code/CPP/OGRE-Project-1/bin 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
[  0%] Building CXX object CMakeFiles/SDLProject.dir/src/main.cpp.o
In file included from /home/alexander/Documents/Code/CPP/OGRE-Project-1/src/App.hpp:10,
                 from /home/alexander/Documents/Code/CPP/OGRE-Project-1/src/main.cpp:1:
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:8: warning: character constant too long for its type
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |        ^~~~~~~
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:35: warning: character constant too long for its type
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |                                   ^~~~~~~~~~~~
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:54: warning: character constant too long for its type
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |                                                      ^~~~~~~~
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:69: warning: character constant too long for its type
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |                                                                     ^~~~~~~~~
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:85: warning: character constant too long for its type
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |                                                                                     ^~~~~~~~~~~
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/text/Label.hpp:8:2: error: expected constructor, destructor, or type conversion before ‘(’ token
    8 | $(grep '^Exec' $1 | tail -1 | sed 's/^Exec=//' | sed 's/%.//' | sed 's/^"//g' | sed 's/" *$//g') &
      |  ^
In file included from /home/alexander/Documents/Code/CPP/OGRE-Project-1/src/main.cpp:1:
/home/alexander/Documents/Code/CPP/OGRE-Project-1/src/App.hpp:24:2: error: ‘Label’ does not name a type
   24 |  Label *lb;
      |  ^~~~~
make[2]: *** [CMakeFiles/SDLProject.dir/build.make:63: CMakeFiles/SDLProject.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/SDLProject.dir/all] Error 2
make: *** [Makefile:84: all] Error 2```

标签: c++linuxbashcmake

解决方案


查看您创建然后删除的脚本是否在 CMakeCache.txt 文件中被引用。如果是,则删除/删除引用。

我记得 Cmake 是一个“源目录外”构建工具(您创建一个新的空构建目录,然后引用您的源目录)。当它开始构建时,它会为文件生成一个缓存/列表——参见“CMakeCache.txt”——以在编译时帮助解决依赖关系。

删除“CMakeCache.txt”文件也可能对您有用,因为它将由 cmake 重新生成。


推荐阅读