Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
fprintf在使用Make编译的C程序中不起作用_C_Makefile_Printf - Fatal编程技术网

fprintf在使用Make编译的C程序中不起作用

fprintf在使用Make编译的C程序中不起作用,c,makefile,printf,C,Makefile,Printf,我有两个C代码相同的文件。我正在编译一个使用Make,另一个直接使用GCC-GCC-NAME.c-o-NAME 在GCC编译的程序中,所有fprintf语句都可以正常工作。在Make编译程序中,只有if语句中的fprintf语句工作。其他的不打印任何东西。我不知道为什么 代码是: #include <stdio.h> #include <stdlib.h> #include <

我有两个C代码相同的文件。我正在编译一个使用Make,另一个直接使用GCC-GCC-NAME.c-o-NAME

在GCC编译的程序中,所有fprintf语句都可以正常工作。在Make编译程序中,只有if语句中的fprintf语句工作。其他的不打印任何东西。我不知道为什么

代码是:

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

#define BUFFER_SIZE 1000                 

int main(int argc, char ** argv) {       
    fprintf(stdout, "test\n");   
    if (argc != 2) {                     
        fprintf(stderr, "You must have one argument: filename or -h\n");
        return 1;
    }   

    if (strcmp(argv[1], "-h") == 0) {    
        fprintf(stdout, "HELP\n"); /*ADD TEXT HERE*/
    }   
    fprintf(stdout, "got to the end\n"); 
    return 0;                            
}
GCC单次运行,带-h输出:

changed text
HELP
got to the end
Make one输出:

HELP

非常感谢您的帮助。

您忘记了makefile中的-c选项:

.
.
.    
wordstat.o: wordstat.c  
    $(COMPILER) $(CCFLAGS) -c wordstat.c
                            ↑ - important!

否则,此行不会生成对象文件,而是生成一个可执行的elf文件a.out,因此可能会导致意外行为,因为您将该文件重新编译到wordstat,并且该文件已编译。

make DEBUG=TRUE不是正确的语法;它应该是make DEBUG=TRUE。但是像这样的递归make可能不是最好的方法。谢谢你的语法修复。我该怎么做呢?我不知道我在做什么;我是个彻头彻尾的新手
.
.
.    
wordstat.o: wordstat.c  
    $(COMPILER) $(CCFLAGS) -c wordstat.c
                            ↑ - important!