compiling multiple files in arduino development environment?

Hello, I'm trying to compile 3 files in Arduino development environment. I keep getting an error in recognizing any functions in the .c file, even if the code is as simple as this:

mysketch:

include hello.h

setup() { hello(); }

hello.h:

void hello(void);

hello.c:

include "hello.h"

void hello(void) { delay(50); }

Do you think there is something wrong with my arduino environment or is there something I am doing wrong here?

I keep getting an error in recognizing any functions in the .c file

Linker errors?

Where are you storing the hello.h and .c files?

Hi! First off, thanks for the replies.

2nd:

Linker errors?
the exact error is:
undefined reference to `hello()

Where are you storing the hello.h and .c files?
I’m creating them as new ‘tabs’ in my sketch. They get saved in the sketch folder. In this case the exact location is:

My Documents\Arduino\sketch_apr05a

I did it again from scratch on another computer and get the exact same result. The compiler refuses to recognize functions that aren’t in the main sketch file. So either I am doing something horribly wrong here or the arduino visual compiler doesn’t support compiling other .c files and I will have to do a makefile or something.

EDIT: see attachments for screen captures of my code and the error I get. Based on my experience with C this should compile, unless I am missing some of the nuances of the compiler that Arduino uses.

sketch.JPG

sketch2.JPG

So either I am doing something horribly wrong here or the arduino visual compiler doesn't support compiling other .c files and I will have to do a makefile or something.

None of the above. You've done nothing horrible and the compiler works fine. The Arduino Sketch is converted to a C++ (cpp) file. The C++ compiler does a thing called "name mangling"; the C compiler does not do this. So, in your Sketch the "hello" function might be actually be "fvhello@v" (or some other nonsense) while in the C file the function name is just "hello".

There are two potential solutions...

  1. Change your dot-C file to a dot-CPP file. I recommend this solution.

  2. Wrap your function declarations in extern "C"...

hello.h:

extern "C" {

void hello(void);

}

[quote author=Coding Badly link=topic=57691.msg414685#msg414685 date=1302056168]

So either I am doing something horribly wrong here or the arduino visual compiler doesn't support compiling other .c files and I will have to do a makefile or something.

None of the above. You've done nothing horrible and the compiler works fine. The Arduino Sketch is converted to a C++ (cpp) file. The C++ compiler does a thing called "name mangling"; the C compiler does not do this. So, in your Sketch the "hello" function might be actually be "fvhello@v" (or some other nonsense) while in the C file the function name is just "hello".

There are two potential solutions...

  1. Change your dot-C file to a dot-CPP file. I recommend this solution.

  2. Wrap your function declarations in extern "C"...

hello.h:

extern "C" {

void hello(void);

}

[/quote]

yup, this did the trick. Thanks a lot!

btw is "name mangling" a technical term? BTW yes I am a C++ noob, all of my education is in C.

btw is "name mangling" a technical term?

I believe so. It's the term I've always seen used.

Thanks a lot!

You are welcome and welcome to the forum.