I try to make a multi file project (with .c and .h) but i can't compile, i have this message: exSousFontion.cpp.o: In function loop':** **C:\Program Files (x86)\Arduino/exSousFontion.ino:11: undefined reference to retourneANumber()'
This is my simple exemple: exSousFonction.ino #include "toto.h" void setup(){ } void loop() {
int A = retourneANumber();* }
And the function i add with the tab option: toto.c #include "Arduino.h" #include "toto.h" int retourneANumber(void) {
return (10);*
}
toto.h int retourneANumber(void);
I beleive the problem is during the link, but i dont understand why ?
But, it is the preconise solution to share a project in several files?
No. The problem is that you are trying to call a C function from a CPP file. That can be done, but extra steps need to be taken.
It's generally far easier to just name the source file with a cpp extension and let the compiler do the name mangling so that the linker can find the function with the name it is looking for in the resulting object file.
If you must use a c extension, you need to add:
extern "C" {
before any function(s) to be called from cpp files, and