在编译一些 Arduino C 文件时出现错误“对 `readArms()' 的 undefined reference ”
代码可以在 paste bin 上找到.
但基本上发生的是:
在我使用的 INO 文件中:
readArms();
在“armfunctions.h”和“armfunctions.c”中声明
.h文件包含
void readArms(void);
还有 .c 文件:
void readArms(void){
float motor1 = 0.0;
int motor = 0;
motor = analogRead(READMOTOR1);
motor1 = (float)motor;
motor1 = (motor1 - 87.0) * (400.0/(1007.0-87.0));
delay(1000);
}
最佳答案
我今天已经为此研究了几个小时,制作并测试了各种草图,并且发现(正如您已经发现的那样)将它们更改为 .cpp
是一种解决方法,但如果您想专门创建一个 c 文件,您必须将原型(prototype)包装在 header 中才能使其编译。有一些关于它的好帖子,但问题的症结在于你的 .h
文件中:
#ifdef __cplusplus
extern "C" {
#endif
void readArms(void);
#ifdef __cplusplus
}
#endif
关于c - 阿杜诺 C : undefined reference to `readArms()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19635007/