While compiling some Arduino C file I get an error "undefined reference to `readArms()'"
在编译一些Arduino C文件时,我收到一个错误“未定义引用`readArms()'”
The code can be found on paste bin.
代码可以在粘贴箱中找到。
But basically what happens is:
但基本上会发生什么:
In the INO file I use:
在INO文件中我使用:
readArms();
Which is declared in "armfunctions.h" and "armfunctions.c"
哪个在“armfunctions.h”和“armfunctions.c”中声明
The .h file contains
.h文件包含
void readArms(void);
And the .c file :
和.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);
}
2 个解决方案
#1
26
I have been researching this for hours today, making and testing various sketches, and have found (as you've already found) changing them to .cpp
is a workaround, but if you want to specifically create a c file, you must wrap the prototypes in the header to get it to compile. There are a few good posts about it, but the crux of the issue, in your .h
file put:
我今天已经研究了几个小时,制作和测试各种草图,并且发现(正如你已经发现的)将它们更改为.cpp是一种解决方法,但是如果你想专门创建一个ac文件,你必须包装原型在标题中让它编译。有一些关于它的好帖子,但问题的症结在你的.h文件中:
#ifdef __cplusplus
extern "C" {
#endif
void readArms(void);
#ifdef __cplusplus
}
#endif
#2
-2
You should use the following in your .C file:
您应该在.C文件中使用以下内容:
void armfunctions::readArms(void)... (the part in front of the :: is your classname in your .h file)
void armfunctions :: readArms(void)...(::前面的部分是.h文件中的类名)
#1
26
I have been researching this for hours today, making and testing various sketches, and have found (as you've already found) changing them to .cpp
is a workaround, but if you want to specifically create a c file, you must wrap the prototypes in the header to get it to compile. There are a few good posts about it, but the crux of the issue, in your .h
file put:
我今天已经研究了几个小时,制作和测试各种草图,并且发现(正如你已经发现的)将它们更改为.cpp是一种解决方法,但是如果你想专门创建一个ac文件,你必须包装原型在标题中让它编译。有一些关于它的好帖子,但问题的症结在你的.h文件中:
#ifdef __cplusplus
extern "C" {
#endif
void readArms(void);
#ifdef __cplusplus
}
#endif
#2
-2
You should use the following in your .C file:
您应该在.C文件中使用以下内容:
void armfunctions::readArms(void)... (the part in front of the :: is your classname in your .h file)
void armfunctions :: readArms(void)...(::前面的部分是.h文件中的类名)