Linker Error

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Linker Error

跳至解决方案
3,079 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
2,033 次查看
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 项奖励
回复
4 回复数
2,033 次查看
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 项奖励
回复
2,033 次查看
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 项奖励
回复
2,034 次查看
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 项奖励
回复
2,033 次查看
PaulRaine
Contributor I

Many Thanks Stanish.  That was the problem. 

 

Regards

 

Paul

0 项奖励
回复