未定义的引用`_fcloseall'

时间:2015-03-06 14:13:02

标签: c windows

我在编写程序时遇到问题。 错误信息是:未定义引用`_fcloseall',我认为它可能是一开始时缺少的库文件。知道我在Windows 8.1 + Cygwin上编程可能也很有用。可能缺少哪个库,或者您是否看到任何其他错误?

以下是代码:

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


void cleanup1();
void cleanup2();

int main(int argc, char *argv[])
{
    FILE * file;
    if(argc < 2){
        printf("\ncommand bsp10085 <file>");
        exit(1);
    }
    assert(atexit(cleanup1) == 0);
    assert(atexit(cleanup2) == 0);
    if((datei = fopen(argv[1], "r")) != NULL){
        printf("\nfile %s is being processed ..",argv[1]);
        fclose(datei);
    }
    else
        printf("\nfile '%s' is missing. ", argv[1]);
}

void cleanup1(){
    printf("\nCleanup the rest");
}

void cleanup2(){
    printf("\nClose all open files");
    fflush(NULL);
    _fcloseall();
}

1 个答案:

答案 0 :(得分:0)

我尝试编译你的代码(虽然在ubuntu中)我也收到了警告:警告:隐式声明函数'fcloseall'[-Wimplicit-function-declaration] fcloseall(); < / p>

我认为如果你添加

#define _GNU_SOURCE 

之前

#include<stdio.h> 

你的程序应该可以正常工作。在我改变了一些其他警告之后,这是你的代码:

#define _GNU_SOURCE
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

void cleanup1();
void cleanup2();

int main(int argc, char *argv[])
{
    FILE *datei;
    if(argc < 2){
        printf("\ncommand bsp10085 <file>");
        exit(1);
    }
    assert(atexit(cleanup1) == 0);
    assert(atexit(cleanup2) == 0);
    if((datei = fopen(argv[1], "r")) != NULL){
        printf("\nfile %s is being processed ..",argv[1]);
        fclose(datei);
    }
    else
        printf("\nfile '%s' is missing. ", argv[1]);
   return 0;
}

void cleanup1(){
    printf("\nCleanup the rest");
}

void cleanup2(){
    printf("\nClose all open files");
    fflush(NULL);
    fcloseall();
}