How do you link in other .c files?

Hi all,

I'm trying to make some external code available as an Arduino library, however in order to do this I have to compile and link in some additional .c files with the sketch.

Unfortunately I can't see how this is done. At the moment when I compile the sketch I get a whole bunch of undefined reference errors.

Looking around on the forum it seems that you need to #include files in a special way or something to get them compiled, but I've tried including the external code's .h files in the sketch and it doesn't make any difference.

Is there some other way you can tell the IDE to compile and link in some additional files?

Do you have header files with the same name as the dot-c files?

I have a library broken up into five source files. Other than putting all the files in the Library's directory, I don't remember doing anything special to get them included in the build.

I was hoping I could avoid sticking them in the same directory as all my own library files to keep things clean.

Looking at the Ethernet library they seem to have used some magic to get it to work, which I think I've figured out. It seems you have to create a "utility" folder and put all your .c and .h files in there, then in your main library .cpp file you need to put 'extern "C" {}' around all the #include lines. (And you just #include "file.h", not utility/file.h)

This seems to work for the most part. There's quite a bit of magic (sometimes files won't build unless the .h file is included in a particular file) but with plenty of fiddling around I think it might be compiling properly...