Multiple definitions of a function

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 I have created a function named "keypad". then I have placed the function in a header file called "keypad.h".

   

then I have used the keypad function all over the different ISRs. when I build the project I get this error:

   

Build error: multiple definition of `keypad'

   

I am quite sure that it is only defined once. so what is the problem?

0 Likes
11 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Maybe Bob can answer this but should not the f() be declared external

   

in other file usage ?

   

 

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please post your project or at least the keypad.h and .c files.

   

Did you use the #ifndef-scheme in your .h -file

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 here is the project:

   

https://drive.google.com/file/d/0BwvX4pp-M0Kyb0FaUU5wRHVqZms/edit?usp=sharing

   

it is a simple keypad component, I have tried putting everything in main.c and it works flawlessly. the problem occured when I divided it among different sources.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@mahmoud

   

There is a function in creator named "Create workspace Bundle" which will create a .zip-file that you can attach here with your post when using internet explorer (chrome does NOT work).

   

I cannot download the folder using your provided link.

   

I am not interested in a working solution, but to see what the error is you have got.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 Right, sorry here it is.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

or not?

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

If all fails send to my email j.meier<at>jmeiersoftware.de

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 reuploading

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

In the header file, just keep the definition of the function) e.g.

   
int funcname(int param);
   

and the define the body of the function in a .c file, e.g.

   
int funcname(int param) {   return param*2; }
   

The you include the .h file whenever needed (just make sure to include it only once always).

0 Likes
Anonymous
Not applicable

I know this is a little late  but thanks for everyone (especially Bob). I am really gratefull for your replies and the problem is solved.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome! Even when late

   

 

   

Bob

0 Likes