0
votes

I've added a new mycode.c and mycode.h file into my IAR Embedded Workbench project. The files compile without error, but the linker fails with the message:

Error[Li005]: no definition for "myfun()" [referenced from C:\MyProj\Debug\Obj\main.o] 

(Some names changed to protect the innocent.)

I checked the .map file, and myfun() does not appear there. Any idea why myfun() is not getting linked?

1

1 Answers

1
votes

Is there any chance your project is a mixed C / C++ project? If so, you need to include the following extern "C" { ... } construct in your .h file (with the obvious name changes...):

// file: mycode.h
#ifndef MYCODE_H
#define MYCODE_H

#ifdef __cplusplus
extern "C" {
#endif

// your declarations go here...
void myfun();

#ifdef __cplusplus
}
#endif

#endif // #ifndef MYCODE_H