how to use additional .c files in a sketch

I am a beginner with the Arduino environment and I need some help figuring out how to use some .c source files in a sketch without creating a library. I tried to find the answer on the forum but I couldn't, I apologize if the solution to my problem is somewhere in the posts and I just missed it.

So, I have a test.h file that contains only:

void doSomething(void);

The test.c file contains:

#include "test.h"

void doSomething(void)
{
      // there should be some code here
}

In my sketch, I have:

#include "test.h"

void setup()
{
  doSomething();
}

void loop()
{
}

I am not sure if this was needed or not but I also went to the Sketch menu and use Add File... to include both .h and .c file.

When I compile I get:

o: In function `setup':
C:\DOCUME~1\coprea\LOCALS~1\Temp\build50525.tmp/Temporary_3386_6704.cpp:6: undefined reference to `doSomething()'


C:\DOCUME~1\coprea\LOCALS~1\Temp\build50525.tmp/Temporary_3386_6704.cpp:8: undefined reference to `doSomething()'

If I understand correctly from the Build Process page, this should work so I am sure I am missing something. Thanks for your help in advance!

beginner--

The problem stems from the fact that you are trying to link a C function from a C++ module, without explicitly declaring that fact. There are several solutions, including:

a) rename test.c to test.cpp
b) remove the #include "test.h" from your main sketch and replace it with

extern "C" void doSomething(void);

c) change the header to the clumsy:

#if defined(__cplusplus)
extern "C"
{
#endif
void doSomething(void);
#if defined(__cplusplus)
}
#endif

etc.

Mikal

Thank you very very much for taking the time to explain this to me, I used the first alternative and it works great.