undefined reference to 'MyFunc'

I just spent a couple of hours figuring this out. Hope this helps you avoid the pain I just went through.

For my project I needed to port in some c code from another embedded device. So I copied the MyOldCode.C from the other project into mine. fixed all the compiler errors for this (different kernal and driver functions). Then tried to call one of the functions in root.c, and was surprised to get “undefined reference to ‘myFunc’” error.

MyFunc was defined. it was in the header file MyOldCode.C was part of the project and so on.

Turns out a .C file is NOT the same as a .c file (case sensitive)

my guess and I’ve wasted enough time on this is a .C file is treated as a C++ file while a .c file is treated as a c file.

Well. i have tried what you are saying… But no errors for me.
Can you please upload you project code?

What ESP version are you using?? i mean NETOS version?
Is it updated to the latest patches.

and try adding this line #include “MyOldCode.C”

Digi ESP for NET+OS

Version: 1.4.0
Build id: 03132009 NET+OS 7.4.2

just tried it again with a new project. Steps I used

  • Create new net OS project
  • right click on the project name in the projects window.
  • Select New - Source file
  • name it Test.C

in test.C copy the following

void myFunc(void) 

in root.c

void myFunc(void); 
void myFunc2(void) { } 

void applicationStart (void) 

[...  default code]


doing the above you get an error on both
myfunc and myFunc2

but if you are using a #include “MyOldCode.C”

that kind of defeats the purpose of a project. if you do that you could name it “MyOldCode.java” or “MyOldCode.gibberish” and it would still build ok

Well i guess you gotta add
void myFunc(void);
in some kinda func.h file and add in both root.c and test.C
and remove void myFunc(void); from root.c

if you declare void myFunc(void); in root.c you gotta define it in root.c itself

Umm, no you don’t. it’s just good programing practice. it avoids the need to maintain the prototype in multiple .c files. For SIMPLE example code that shows the problem, the above is perfectly legal.

Think of #include “myFile.xxx” as a copy/paste operation tha happens at compile time. myFile.xxx gets copied into whatever file has the #include “myFile.xxx”

More information:

while looking for something else I found that .C is definitely compiled as a C++ file. you can see the setting by right clicking your project selecting properties and then opening the “C/C++ file types” settings