0

i was programming a Self Balancing Robot, I am writing the code in vscode using platformio extension.

when i put the code i need to get the angle out of the gyro in another file (named angle.c) and including it in the main program, the ide throws with error, in every line I use the Wire library in the angle.c, however same code copy and paste it in the main program and it works.

P.S. the angle.c is just a file of functions and doesnot have any class.

  • Check the command when compiling angle.c. Is that that right compiler? Try the extension .cpp instead. – Mikael Patel Jul 19 at 11:30
  • the compiler is checked, i'll try the .cpp extension – Allaw Hussein Jul 19 at 11:31
  • you can't include Wire.h in .c . Wire.h defines a class – Juraj Jul 19 at 11:40
  • that is it you are right, no please post it as an answer, so that i can accept it – Allaw Hussein Jul 19 at 12:17
  • the solution is to change the extension into .cpp because Wire.h defines classes – Allaw Hussein Jul 19 at 12:19
1

A .c file is compiled with C compiler. If you include Wire.h which contains a class definition, the C compiler doesn't understand it and generates errors.

If your angle.c file doesn't have C code not compatible with C++, then change the extension of the file to .cpp and it will be compiled with C++ compiler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.