Linker Error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linker Error

Jump to solution
1,586 Views
PaulRaine
Contributor I

Hi,

 

MCF5282, CW 6.3

 

I get the following error when trying to build my project.

 

Link Error : Undefined  : <function name>

 

The calling function is in a file which contains the relevant .h file and right-clicking on the function name allows me to jump to the relevant peice of code.

The code compiles OK, and works in another project.

 

Does anyone have any ideas on how to track down the source of the error?

 

Although the 2 projects are different, the order in which the relevant files are linked is the same.

 

Thanks

 

Paul

Labels (1)
0 Kudos
1 Solution
540 Views
CompilerGuru
NXP Employee
NXP Employee

To call functions implemented in C++ from C code, the C++ code has to explictely use C linkage.

So there has to be something like this in the header file:

// ApplicationTasks.h// ....#ifdef __cplusplusextern "C" {#endifextern int input_get(void); #ifdef __cplusplus}#endif

 



Is the C linkage declaration present?

View solution in original post

0 Kudos
4 Replies
540 Views
stanish
NXP Employee
NXP Employee

Paul,

this error indicates that the linker is not able to find  implementation of a function in the project.
 
1. I'd suggest you first to check if the file that includes this function is available for Linker.
("Linking Order" tab of project inspector)

 
2. Perhaps IDE cache is not up-to-date so try to remove all object code (Ctrl -)and rebuild.

3. please verify that called function is not "static"

 

If it doesn't help could you post here complete Linker error message?

 

Stanish

0 Kudos
540 Views
PaulRaine
Contributor I

Hi Stanish, thanks for replying.

 

1. Yes the file does appear in the Link Order Tab.

2. I have tried removing all of the object code but this still doesn't help.

3. The function is not static.

 

The message is: -

 

Link Error : Undefined : "input_get"

Referenced from "DigitalInput_Get" in digital_io.c

 

The function being called resides in a file called ApplicationTasks.cpp and I have tried moving this above the calling file in the Link order tab, but this made no difference.

 

Basically, I have several projects which use common device drivers (such as digital_io.c) and application specific code (such as ApplicationTasks.cpp).  The linking works in another application (seperate CW project)

 

Paul

0 Kudos
541 Views
CompilerGuru
NXP Employee
NXP Employee

To call functions implemented in C++ from C code, the C++ code has to explictely use C linkage.

So there has to be something like this in the header file:

// ApplicationTasks.h// ....#ifdef __cplusplusextern "C" {#endifextern int input_get(void); #ifdef __cplusplus}#endif

 



Is the C linkage declaration present?
0 Kudos
540 Views
PaulRaine
Contributor I

Many Thanks Stanish.  That was the problem. 

 

Regards

 

Paul

0 Kudos