我在 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/