Although I'm pretty experienced with programming AVR's, I have a very basic question the arduino IDE. I'm trying to include a header file, but no matter what I do, I keep getting the following error:
"undefined reference to `test()'"
Well I already found a (sort of) solution. When I rename test.c to test.cpp, it works.
However, I'm not using C++ and since I want my libraries to be usable in avrstudio too, I just want to use plain c files. Does anyone know how I can arrange that in the arduino IDE?
C++ allows for function overloading, where one function, like Serial.print(), can print characters, arrays of characters, ints, array of ints, etc.
To support this, the C++ compiler performs a process known as name mangling, where the function name is actually constructed from the name of the function and the types of all the arguments.
C does not support function overloading, so it does not support name mangling.
The C++ compiler is invoked when the main program is C++, which is what the sketch is converted to.
You can tell the C++ compiler not to perform name mangling for a function, by using extern "C" in front of each function name in the header file:
extern "C" void test();
If there are multiple functions you want to define, you can do this:
The difference between <> and "" is where the compiler looks for header files. The "" means local (in the sketch folder). The <> is for library files (not in the sketch directory). Some compilers are not rigorous in enforcing this distinction.
Now I've got another problem:
When I try to include SD.h in my library, the compiler says "No such file or directory". But when I include it in the main-file, i get no complaints.
Does anybody have an idea how that comes?