Arduino C: undefined reference to `readArms () '

When compiling some Arduino C file, I get the error message "undefined reference to` readArms () '"

The code can be found on the insert bin .

But basically the following happens:

In the INO file, I use:

readArms(); 

What 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); } 
+6
source share
2 answers

I study this for hours today, making and testing various sketches, and found (as you already found) changing them to .cpp is a workaround, but if you want to specially create an ac file, you have to wrap the prototypes in the header to force it to compile . It has some good posts, but the gist of the problem is in your .h file:

 #ifdef __cplusplus extern "C" { #endif void readArms(void); #ifdef __cplusplus } #endif 
+24
source

You should use the following in your .C file:

void armfunctions :: readArms (void) ... (the part before :: is your class name in your .h file)

-2
source

Source: https://habr.com/ru/post/956871/


All Articles