我不熟悉 make 系统。当我尝试执行如下程序时,没有问题:
./prog.out arg1 arg2 arg3
当我决定使用 make 时,我将以下脚本添加到 makefile
parse ${parameters}:
./prog.out ${parameters}
当它运作良好时,这很奇怪;
make parse parameters="aaa bbb ccc"
这些字符:'(' 和 ')' 会产生错误!
make parse parameters="( d , ( d , ( d , d ) ) )"
Makefile:7: target `(' given more than once in the same rule.
Makefile:7: target `d' given more than once in the same rule.
Makefile:7: target `,' given more than once in the same rule.
Makefile:7: target `(' given more than once in the same rule.
Makefile:7: target `d' given more than once in the same rule.
Makefile:7: target `,' given more than once in the same rule.
Makefile:7: target `d' given more than once in the same rule.
Makefile:7: target `)' given more than once in the same rule.
Makefile:7: target `)' given more than once in the same rule.
./prog.out ( d , ( d , ( d , d ) ) )
/bin/sh: 1: Syntax error: "(" unexpected
make: *** [parse] Error 2
但这很好用;
./prog.out "( d , ( d , ( d , d ) ) )"
制作版本是3.81
有什么想法吗?
最佳答案
parse ${parameters}:
./prog.out ${parameters}
上面的 makefile 片段创建了一个名为 parse
的目标,并为变量 parameters
扩展中的每个单词创建了一个目标。
因此在您的调用中 make parse parameters="aaa bbb ccc"
该行扩展为 parse aaa bbb ccc:
并且您最终定义了四个目标 parse
、aaa
、bbb
和 ccc
。
通过调用 make parse parameters="( d , ( d , ( d , d ) ) )"
它扩展为 parse ( d , ( d , ( d , d ) ) ):
并定义目标 parse,
d,
(,
,and
)with
d被列出四次,
,三次,
(三次
and )
三次。 (这就是为什么 make 提示目标被重新定义。
如果您只想将 parameters
用作运行命令中的变量,那么您根本不需要在目标行中使用它。
parse:
./prog.out "${parameters}"
然后使用
make parse parameters="aaa bbb ccc
或
make parse parameters="( d , ( d , ( d , d ) ) )"
关于c++ - Makefile:7:目标(在同一规则中多次给出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27241041/