【问题标题】:How to select *.c files with Makefile?如何使用 Makefile 选择 *.c 文件?
【发布时间】:2013-03-03 00:03:42
【问题描述】:

这是一个愚蠢的问题,但这是我第一次使用Makefile。 我在选择文件时遇到问题。当我使用这个命令时,

target1:

     $(CC) -o target *.c

效果很好。 但这不起作用,

SRCS = dir1/*.c
target1:

     $(CC) -o target $(SRCS)

并吐出这个错误。

clang: error: no such file or directory: 'dir1/*.c'

显然这是因为我的变量 SRCS 在传递之前被转义了。 如何让 Makefile 按原样传递字符串?还是有另一种传统/设计的方法来做到这一点? (按模式选择文件)

【问题讨论】:

标签: makefile


【解决方案1】:

您可以使用wildcard 关键字来选择所有匹配特定模式的文件,如下所示:

SRCS = $(wildcard dir1/*.c)
target1:

     $(CC) -o target $(SRCS)

【讨论】:

    【解决方案2】:
    SRCS := $(shell echo dir1/*.c)
    target1:
        $(CC) -o target $(SRCS)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 2012-12-09
      • 2017-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多