c - 从 makefile 设置标志的问题

标签 c makefile flags

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv) {

#ifdef DEBUG
  printf("Debug!\n");
#endif

  printf("hello world\n");

}

生成文件:

CC=gcc-5

CFLAGS=-I

DEPS=foo.c

main: $(DEPS)
    $(CC) -o foo $(DEPS) $(CFLAGS).

debug: CFLAGS += -DDEBUG
debug: main

当我运行 make debug

gcc-5 -o foo foo.c -I -DDEBUG.
> ./foo 
hello world

为什么我没有看到“调试!”?

最佳答案

-I 选项需要一个参数,现在是 -DDEBUG.。要么删除 -I 选项,要么为其提供一个参数。我建议删除它,因为我看不到任何值得将目录添加到包含搜索路径的内容。

关于c - 从 makefile 设置标志的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33516839/

相关文章:

c++ - 我们如何使用动态规划解决子串匹配检查

c - 我如何解释这个简单的 C 代码的输出?

makefile - 动态目标中的目标变量

c - gcc:错误:Makfile 中无法识别的命令行选项 '-Wl'

c - 我如何在 ubuntu 上用 Makefile 编译 C 程序?

batch-file - 设置 cmd.exe/V :ON flag without starting new instance

Java:标记/标记文件

c - 我的代码在长文本时崩溃?从文件中逐个字符地读取到 C 中的动态字符数组

c++ - 是否可以在不使用 ‘undef’ 的情况下重新定义宏?

c++ - 带有名称的枚举标志