CodeWarrior 10.6链接器错误

时间:2014-11-20 03:21:30

标签: c embedded linker-errors codewarrior

我是C和CodeWarrior嵌入式编程的新手,我想知道是否有人可以帮我解决问题。似乎当我去构建我的项目时,我得到了一些像这样的链接器错误:

**** Build of configuration FLASH for project test ****

"C:\\Freescale\\CW MCU v10.6\\gnu\\bin\\mingw32-make" -j12 all 
'Building target: test.elf'
'Executing target #9 test.elf'
'Invoking: ColdFire Linker'
"C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf" -o "test.elf" @@"test.args"   
C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf|Linker|Error
>Undefined : "tFlag"
>Referenced from "TI1_OnInterrupt" in
mingw32-make: *** [test.elf] Error 1
C:/Freescale/CW MCU v10.6/MCU/ColdFire_Tools/Command_Line_Tools/mwldmcf|Linker|Error
>Link failed. 

我正在使用带有MCF51EM系列微控制器的DEMOEM板。任何建议都将不胜感激。

谢谢,

泰勒

3 个答案:

答案 0 :(得分:3)

您缺少C语言范围概念。您定义的tFlag变量是main函数中的局部变量。它被分配在主功能堆栈存储器中,只有主功能可以通过它的名称来查看它。解决这个问题需要的是将tFlag定义为文件中的全局变量,包含主函数,并在文件中将其外部包含TI1_OnInterrupt函数。您可以在此link找到有关C变量范围的更多信息以及有关存储类的更多信息 - extern就是其中之一 - 在此link

答案 1 :(得分:2)

您应该检查功能TI1_OnInterrupt 这个函数使用一个变量tFlag,搜索这个变量,它在某个地方用类似的东西声明 extern int tFlag;

但似乎缺少定义 你需要添加
ìnt tFlag;

来自您发布的代码:

void main(void)
{
  bool tFlag = FALSE;
...

tFlag变量仅在main()中可见 你应该把它移到函数之外

答案 2 :(得分:0)

我相信我已经做到了。这是我的源代码。

main.c中:

/* ###################################################################
**     Filename    : main.c
**     Project     : test
**     Processor   : MCF51EM256CLL
**     Version     : Driver 01.00
**     Compiler    : CodeWarrior ColdFireV1 C Compiler
**     Date/Time   : 2014-11-19, 17:54, # CodeGen: 0
**     Abstract    :
**         Main module.
**         This module contains user's application code.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file main.c
** @version 01.00
** @brief
**         Main module.
**         This module contains user's application code.
*/         
/*!
**  @addtogroup main_module main module documentation
**  @{
*/         
/* MODULE main */


/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "Bit1.h"
#include "TI1.h"
/* Include shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

void main(void)
{
  bool tFlag = FALSE;

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  for(;;)
  {
      if(tFlag == TRUE)
      {
          Bit1_NegVal();
          tFlag = FALSE;
      }
  }

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.3 [05.09]
**     for the Freescale ColdFireV1 series of microcontrollers.
**
** ###################################################################
*/

和events.c:

/* ###################################################################
**     Filename    : Events.c
**     Project     : test
**     Processor   : MCF51EM256CLL
**     Component   : Events
**     Version     : Driver 01.02
**     Compiler    : CodeWarrior ColdFireV1 C Compiler
**     Date/Time   : 2014-11-19, 17:54, # CodeGen: 0
**     Abstract    :
**         This is user's event module.
**         Put your event handler code here.
**     Settings    :
**     Contents    :
**         No public methods
**
** ###################################################################*/
/*!
** @file Events.c
** @version 01.02
** @brief
**         This is user's event module.
**         Put your event handler code here.
*/         
/*!
**  @addtogroup Events_module Events module documentation
**  @{
*/         
/* MODULE Events */

#include "Cpu.h"
#include "Events.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

/*
** ===================================================================
**     Event       :  TI1_OnInterrupt (module Events)
**
**     Component   :  TI1 [TimerInt]
**     Description :
**         When a timer interrupt occurs this event is called (only
**         when the component is enabled - <Enable> and the events are
**         enabled - <EnableEvent>). This event is enabled only if a
**         <interrupt service/event> is enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/

void TI1_OnInterrupt(void)
{
  extern bool tFlag;

  tFlag = TRUE;

}

/* END Events */

/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.3 [05.09]
**     for the Freescale ColdFireV1 series of microcontrollers.
**
** ###################################################################
*/

我觉得我错过了一些简单的事情。谢谢你的回复!