简体   繁体   English

为什么bash / echo在此CMake脚本中不起作用?

[英]Why doesn't bash/echo work in this CMake script?

My CMakeLists.txt correctly builds my_target . 我的CMakeLists.txt可以正确构建my_target

I tried adding this dummy command as a trial post-build step: 我尝试添加此虚拟命令作为试用的构建后步骤:

 ADD_CUSTOM_COMMAND (
        TARGET my_target POST_BUILD
        COMMAND "echo I made `ls ${MY_DIR} | wc -l` things")

When I run make my_target it fails (after building) with 当我运行make my_target它会失败(生成后)

/bin/sh: 1: echo I made `ls /foo/bar | wc -l` things: not found

If I copy-paste the part from "echo" to "things" into a shell it runs fine 如果我将“ echo”部分复制到“ things”中,然后粘贴到外壳中,它将运行良好

I made 3 things

The "/bin/sh: 1" prefix suggests that a shell is being run with "echo..." as its command, and I tried changing "echo" to "bash echo" so why doesn't this work? “ / bin / sh:1”前缀表明正在使用“ echo ...”作为其命令运行外壳程序 ,而我尝试将“ echo”更改为“ bash echo”,那么为什么这样做不起作用?

/bin/sh: 1: echo I made `ls /foo/bar | wc -l` things: not found

The error message means that something is trying to execute a command called, literally, with spaces and ticks, echo I made `ls /foo/bar | wc -l` things 该错误消息表示某人正在尝试执行一个命令,该命令的字面意思是空格和刻度,并echo I made `ls /foo/bar | wc -l` things echo I made `ls /foo/bar | wc -l` things . echo I made `ls /foo/bar | wc -l` things

So it looks like cmake is passing your whole quote string as the executable. 因此,看起来cmake正在将整个报价字符串作为可执行文件传递。 Removing the outer quotes should fix that. 删除外引号应该可以解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM