Undefined Reference for defined function

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

cross mob
lock attach
Attachments are accessible only for community members.
Bigby
Level 2
Level 2
25 sign-ins 10 sign-ins 5 replies posted

Hello,

I need help as I ran out of options.

I added a keypad.c and a keypad.h file to my project as I usual do.
Added include guards etc.
Function prototypes are in keypad.h and definition in keypad.c

When I call the function Key_KeypadInit() in main.c there is no error icon, but when I compile, it says "undefined reference".

I already tried to rename the files (as I do the same things in other files, where it works) and deleted code lines until the project compiles with no errors. Once I deleted many code lines and it worked. Then I tried to delete code lines one by one but the error still exists.

I add this stripped version of the project, so maybe you can have a look and find out what the problem is.

Thanks in advance.

 

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

sefu,

I have reproduced your results.  There is a simple solve for your issue.

The issue is you have two C files called "keypad.c" and keypad.h" AND you have a component in your TopDesign named "Keypad".

When the application phase compiles the TopDesign to generate the appropriate .c and .h files, the component "Keypad" generates "Keypad.c" and Keypad.h" files.  These file names conflict with the ones you added.

I changed the component name to "Keypad0" and changed the Keypad_ClearInterrupt() reference to Keypad0_ClearInterrupt().  This compiled with NO ERROR.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

2 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

sefu,

I have reproduced your results.  There is a simple solve for your issue.

The issue is you have two C files called "keypad.c" and keypad.h" AND you have a component in your TopDesign named "Keypad".

When the application phase compiles the TopDesign to generate the appropriate .c and .h files, the component "Keypad" generates "Keypad.c" and Keypad.h" files.  These file names conflict with the ones you added.

I changed the component name to "Keypad0" and changed the Keypad_ClearInterrupt() reference to Keypad0_ClearInterrupt().  This compiled with NO ERROR.

Len
"Engineering is an Art. The Art of Compromise."
Bigby
Level 2
Level 2
25 sign-ins 10 sign-ins 5 replies posted

Hi Len,

thanks for your answer. I had a hunch that this was a naming problem. But since the error remained after renaming my files I discarded this idea. Of course I had also renamed the component. Somehow I did not realize that the issue was a conflict between my files and the automatically generated component files.

Your answer is very much appreciated.

Cheers.

0 Likes