c++ - Makefile:7:目标(在同一规则中多次给出

标签 c++ makefile

我不熟悉 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 aaabbbccc

通过调用 make parse parameters="( d , ( d , ( d , d ) ) )" 它扩展为 parse ( d , ( d , ( d , d ) ) ): 并定义目标 parse,d,(,,and)withd被列出四次,三次,(三次 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/

相关文章:

c++ - 我如何让 QtCreator 为调试/发布制作一个单独的 Makefile?

c++ - 无法使用 makefile 编译

c++ - 尝试编译qt项目时编译错误

c++ - 如何为类的每个接口(interface)单独定义一些函数?

c++ - 如何运行一段代码,使其不会在 QtQuick 中窃取所有焦点?

c++ - 是否调用函数指针来生成代码未定义的行为?

c++ - 由于未定义对 'deflateEnd' 的引用,无法使用 GCC 构建 C 应用程序

c++ - 在树中找到一个节点并替换为具有更新私有(private)成员的新节点

c++ - 如何在进程外客户端中获取免注册 COM 对象代理

java - jenkins 完成成功而 make 命令失败