# undefined reference to 'MyFunc'

**URL:** <https://forums.digi.com/t/undefined-reference-to-myfunc/6123>\
**Category:** NET+OS\
**Created:** [February 17, 2011, 9:36pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123 "2011-02-17T21:36:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pBoucher](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pBoucher](https://forums.digi.com/u/pBoucher)\
**Post date:** [February 17, 2011, 9:36pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/1 "2011-02-17T21:36:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bobthomas13](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bobthomas13](https://forums.digi.com/u/bobthomas13)\
**Post date:** [February 18, 2011, 9:49am UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/2 "2011-02-18T09:49:22Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![pBoucher](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pBoucher](https://forums.digi.com/u/pBoucher)\
**Post date:** [February 18, 2011, 6:36pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/3 "2011-02-18T18:36:17Z")

</div>

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

```auto

void myFunc(void) 
{ 
     myFunc2(); 
}

```

in root.c

```auto

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

void applicationStart (void) 
{ 
myFunc();

[... 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

---

<div class="post-metadata">

**Author:** ![bobthomas13](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@bobthomas13](https://forums.digi.com/u/bobthomas13)\
**Post date:** [February 21, 2011, 2:18pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/4 "2011-02-21T14:18:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pBoucher](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pBoucher](https://forums.digi.com/u/pBoucher)\
**Post date:** [February 22, 2011, 2:05pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/5 "2011-02-22T14:05:28Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![pBoucher](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@pBoucher](https://forums.digi.com/u/pBoucher)\
**Post date:** [February 28, 2011, 3:59pm UTC](https://forums.digi.com/t/undefined-reference-to-myfunc/6123/6 "2011-02-28T15:59:04Z")

</div>

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
