我有以下声明
FILE *fptr;
FILE *optr;
在算法中 我在 main.c 中有 main 打开这些文件。 如果我将声明放在头文件中,就会出现上述错误。如果我把它放在 main.c 中,就会出现多个定义错误,例如
src\main.o:main.c:(.bss+0xc88): multiple definition of <code>rcount'
src\new_algo.o:new_algo.c:(.bss+0xc88): first defined here
src\main.o:main.c:(.bss+0xc8c): multiple definition of</code>condi'
src\new_algo.o:new_algo.c:(.bss+0xc8c): first defined here
最佳答案
有点像你 (1) 没有包含 <stdio.h>
你在哪里使用 FILE
, 和/或 (2) 有一些非 static
可执行代码或非 extern
header 中的变量定义(和/或 #include
是一个 C 文件)。
第一个通常会导致 FILE
不被定义(或者在某些情况下被 typedef
定义为不存在的类型)。第二个会导致在包含文件的每个翻译单元中定义内容,这会使链接器感到困惑。
修复:(1) #include <stdio.h>
在文件中 FILE
被使用,并且 (2) 将共享定义从 header 移动到 .c 文件中(和/或将它们声明为 static
或 extern
视情况而定),并且永远只有 #include
.h 文件。
关于c - 错误 : expected '=' , ',' , ';' , 'asm' 或 '__attribute__' 在 C 中的 '*' token 之前,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575700/