我正在使用名为lib.h
的标头来组织我的源代码。标题如下:
#define TOT_REP 10
#define TOT_PAT 10
#define TIME_REP 15
源文件包含标题,但是当我用gcc编译时,我得到了这个:
error: ‘TIME_REP’ undeclared (first use in this function)
所以我尝试用gcc -E -dM
进行编译,我得到了类似的结果:
...
#define SIGUSR2 12
#define TIME_REP 15
#define ____mbstate_t_defined 1
#define __SIGRTMIN 32
...
我也尝试过使用gcc -E
并在输出中发现宏已正确替换为其值。
我该怎么做才能解决这个问题?
编辑:使用TIME_REP的代码是:
while((!ending|| *(shmAddress+0)!=0)&& quitSignal==0){
totFolder=0;
buf=(char*)calloc(2,sizeof(char));
patientString=(char*)calloc(2,sizeof(char));
sleep(TIME_REP);
while(read(fd,buf,sizeof(char))>0){
/*read from a file and get some data*/
}
}
编辑2:我试图重命名lib.h并且它现在似乎工作但我只是无法理解为什么如果用gcc -E -Dm找到宏然后我就无法编译代码。
无论如何回答Woodrow Barlow:
我有lib.h和rep.c,rep.c包括lib.h和其他标题:
#include <stdio.h>
#include <stdlib.h>
#include <sys/shm.h>
#include <unistd.h>
#include <string.h>
#include "ReaderWriter.h"
#include "lib.h"
要编译我使用gcc rep.c -o rep -Wall -pedantic