Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arduino C: undefined reference to `readArms()'

While compiling some Arduino C file I get an error "undefined reference to `readArms()'"

The code can be found on paste bin.

But basically what happens is:

In the INO file I use:

readArms();

Which is declared in "armfunctions.h" and "armfunctions.c"

The .h file contains

void readArms(void);

And the .c file :

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);
}
like image 430
DutchGabber Avatar asked Oct 28 '13 12:10

DutchGabber


1 Answers

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:

#ifdef __cplusplus
extern "C" {
#endif

void readArms(void);

#ifdef __cplusplus
}
#endif
like image 168
Madivad Avatar answered Nov 11 '22 22:11

Madivad