我在编译程序时遇到麻烦。
错误消息是:未定义对_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();
}
最佳答案
我试图编译您的代码(尽管在ubuntu中),但我也得到了警告:警告:函数'fcloseall'的隐式声明[-Wimplicit-function-declaration] fcloseall();
我认为,如果您添加
#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();
}
关于c - 未定义对_fcloseall的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28900601/