CodeWarrior 10.6 Linker Error

2.8k views Asked by At

I am new to embedded programming in C and CodeWarrior and I was wondering if any one could help me with my problem. It seems when I go to build my project I get some kind of linker error like this:

**** 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. 

I am using a DEMOEM board with the MCF51EM family microcontroller. Any advice would be greatly appreciated.

Thank you,

Tyler

3

There are 3 answers

0
jeb On

You should inspect the function TI1_OnInterrupt.
This function uses a variable tFlag, search this variable, it is declared somewhere with something like
extern int tFlag;

But it seems that the definition is missing.
You need to add
ìnt tFlag;

From your posted code:

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

The tFlag variable is visble only in main().
You should move it outside of the function

1
heyItsTy1992 On

I believe i have done that correctly. Here is my source code that i have.

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.
**
** ###################################################################
*/

and 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.
**
** ###################################################################
*/

I feel like i'm missing something simple. Thank you for your reply!

0
وليد تاج الدين On

You are missing the C language scope concept. The tFlag variable as defined by you is a local variable in the main function. It's allocated in the main function stack memory and only the main function can see it by it's name. What you need to solve this problem is to define the tFlag as a global variable in the file conatins the main function and to extern it in the file contains the TI1_OnInterrupt function. you can find more about C variables scope at this link and about storage classes - the extern is one of them - at this link.