文件指针错误未定义

Error with file pointer not defined

我有一个文件 a.ca.h 作为支持模块,具有其他文件的功能。

在这些函数中,我必须打开一个文件并执行读取数据、写入数据、关闭它等功能。

出于这些目的,我在 a.c 中通过

给出了文件指针的全局声明
static FILE* pFile; 

并直接使用pFile

编译器抛出的错误类似于:

"pFile" not defined in the function

这是怎么回事?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <arpa/inet.h>

#define path "/tmp/diag.log"

FILE* pFile;

void a(bool value) {
    if (value) {
            pFile = fopen (path,"a");
      return;
    }
    else if (!value) {
        fclose (pFile);
    }
}

void b(bool value) {
  if(value)
  {
  fprintf (pFile,"%s",message);
  }
  }

更新: 错误是我的 makefile 正在从构建目录中获取文件并且更改没有得到 reflected.Thanks 很多帮助

如果您尝试从另一个编译单元中使用此 static FILE* pFile,请删除 static

在其他文件中添加:

 extern FILE *pfile;