c - 如何将参数传递给 makefile

标签 c makefile arguments

我在 Codeblocks 中编写了一个 C 程序,为了进行编译,我使用了自定义 makefile。我从 Codeblocks 内部构建代码,它工作正常,直到我添加参数(在 Codeblocks 或终端中)并且它们不会传递给程序。我应该在 makefile 中添加什么来考虑参数?特此声明

c代码

#include <stdio.h>
#include <math.h>

int main(const int argc, const char * const argv[])
{
    printf("\n%c\n", argv[0]);
    return 0;
}

和生成文件:

CC = gcc
CFLAGS = -c -Wall
LDFLAGS = -lm

 all: Release

Debug: CFLAGS += -g
Debug: K

Release: K

K: K.o
    $(CC) -o K K.o $(LDFLAGS)

K.o: K.c
    $(CC) $(CFLAGS) K.c -o K.o

clean:
    rm -f K.o K

最佳答案

如图所示的程序将不会打印命令行上传递的任何参数。 argv[0] 通常是程序的名称,%c 也是单字符格式,您需要 %s。

试试这个:

for(int i=1; i<argc; i++)
  printf("%s\n", argv[i]);

关于c - 如何将参数传递给 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57126026/

相关文章:

检查这是否为空

c - 显示 n 次单位根的程序(C 编程)

c++ - Makefile 给我一个错误 - 没有这样的文件或目录

c - 我似乎无法让我的 C 程序接受输入(直角棱柱计算器)

makefile - Sphinx 的默认 Makefile

java - 如何制作一个makefile只用于编译一些java文件?

ruby-on-rails - 在 finder 方法上出现 "wrong number of arguments"错误

linux - 如何指定 scons 中使用的 linux 程序集的命令行 args 和 liker?

c - 如何使 printf 从右到左

c - 简单的多线程,无需getch