我有众所周知的错误:
implicit declaration of function 'STLINKReadSytemCalls' [-Wimplicit-function-declaration]
implicit declaration of function 'printf' [-Wimplicit-function-declaration]
incompatible implicit declaration of built-in function 'printf'
并且 Eclipse(更准确地说是 Atollic TrueStudio)添加:
include '<stdio.h>' or provide a declaration of 'printf'
阅读数十亿的帖子询问如何在 SO 上解决这个问题,似乎三个问题可能会导致这些错误:
- 函数在 main 之后定义;
- 包含使用函数所需的标头
#ifndef
,#define
并且#endif
没有正确包装头文件
我发现了一个帖子,其中有人似乎有这个错误,并在修复它后说 Eclipse 是问题所在。虽然找不到主题,但他的解决方案对我不起作用。这就像单击功能,source -> add includes。
主程序
int main(void) {
if (STLINKReadSytemCalls() == 1)
printf("Error in system calls.\n");
return 0;
}
文件处理.c
#include "../header/fileProcessing.h"
int STLINKReadSytemCalls(void) {
// mainly system calls
}
文件处理.h
#ifndef FILEPROCESSING_H_
#define FILEPROCESSING_H_
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int STLINKReadSytemCalls(void);
#endif /* FILEPROCESSING_H_ */
最令人困惑的部分是代码确实有效。我有以下输出:
STM32 ST-LINK CLI v3.0.0.0
STM32 ST-LINK Command Line Interface
No ST-LINK detected
Unable to connect to ST-LINK!
Error in system calls.
一切似乎都很好,但编译器一直在大喊大叫。如果需要,我将添加函数的主体,但我没有看到任何线索表明函数的主体可能导致包含错误。我一定是遗漏了一些如此明显的东西,以至于当我看到它时,我会像从未有过的那样自我捂脸;但我已经花了几个小时,我希望这很明显变得越来越薄。
哦,昨天使用相同的包含路径和相同的目录构建它工作得非常好。我真的不知道从那以后发生了什么变化。