I have used arduino in several projects and I am encountered with one certain problem again and again. I'm totally fed up with this an wrote a very short example, to show it to you. Please have a look:
If I try to compile this code, I get the following error:
sketch_jan23a.cpp.o: In function setup': C:\Program Files (x86)\arduino-1.0.3/sketch_jan23a.ino:7: undefined reference to f()'
What is the problem? I read several articles and books concerning how to program header files. I can't find any mistake. And it happens everytime I try to split a program in several files. I have found a workaround: including the .c instead of .h
PaulS:
Why are you not using the cpp extension, instead?
Awesome, if I rename the lib.c to lib.cpp, it works. Could you please send me a link, where I can find more information to this problem and the "special handling"?
Just google calling C functions from C++. You need to tell the C++ compiler not to perform name mangling on the C functions. The C compiler doesn't, so the linker can find the name-mangled function in the object module.