Linker Error

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,570件の閲覧回数
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 解決策
1,524件の閲覧回数
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 返答(返信)
1,524件の閲覧回数
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 件の賞賛
返信
1,524件の閲覧回数
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 件の賞賛
返信
1,525件の閲覧回数
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 件の賞賛
返信
1,524件の閲覧回数
PaulRaine
Contributor I

Many Thanks Stanish.  That was the problem. 

 

Regards

 

Paul

0 件の賞賛
返信