error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token in C
I have the following declarations
FILE *fptr;
FILE *optr;
in algo.h I have the main in main.c which opens these files. I get the above error if I put the declarations in the header file. If I put it in the main.c, then I get mutiple definition errors like
src\main.o:main.c:(.bss+0xc88): multiple definition of
rcount'
src\new_algo.o:new_algo.c:(.bss+0xc88): first defined here
src\main.o:main.c:(.bss+0xc8c): multiple definition of
condi'
src\new_algo.o:new_algo.c:(.bss+0xc8c): first开发者_JAVA技巧 defined here
Kinda sounds like you (1) haven't included <stdio.h>
where you're using FILE
, and/or (2) have some non-static
executable code or non-extern
variable definitions in your headers (and/or are #include
ing a C file).
The first would typically cause FILE
not to be defined (or to be typedef
'd to a type that doesn't exist, in some cases). The second would cause stuff to be defined in each translation unit that includes the file, which would confuse the linker.
To fix: (1) #include <stdio.h>
in the file where FILE
is used, and (2) move shared definitions from the headers into a .c file (and/or declare them as static
or extern
as appropriate), and only ever #include
.h files.
What you have in algo.h is a definition not a declaration. If you have FILE *fptr; FILE *optr; in both the source and the header file then you are declaring the variables twice.
You need:
algo.h
extern FILE *fptr;
extern FILE *optr;
algo.c
FILE *fptr;
FILE *optr;
Sounds like you're not including stdio. Add
#include <stdio.h>
in your header file above those declarations.
The linker errors have nothing to do with the FILE
variables you posted.
There are two variables your source, named rcount
and condi
, that according to the linker is defined in both your source files. The reason is, I guess, that you define those variables in a header file that is included in both source files. Some old compilers still can't handle that.
精彩评论