10

在编译一些 Arduino C 文件时,我收到一个错误“未定义对‘readArms()’的引用”

代码可以在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);
}
4

2 回答 2

28

我今天已经研究了几个小时,制作和测试了各种草图,并且发现(正如您已经发现的那样)将它们更改为.cpp是一种解决方法,但是如果您想专门创建 ac 文件,则必须将原型包装在头文件让它编译。有一些关于它的好帖子,但问题的症结在于您的.h文件中:

#ifdef __cplusplus
extern "C" {
#endif

void readArms(void);

#ifdef __cplusplus
}
#endif
于 2014-01-22T07:09:21.960 回答
-2

您应该在 .C 文件中使用以下内容:

void armfunctions::readArms(void)... ( :: 前面的部分是您在 .h 文件中的类名)

于 2014-11-12T15:06:56.470 回答