我是用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板。任何建议都将不胜感激。
谢谢,
泰勒
发布于 2014-11-22 08:16:37
你错过了C语言作用域的概念。您定义的tFlag变量是main函数中的局部变量。它被分配在主函数堆栈内存中,只有主函数可以通过它的名称看到它。您需要解决的问题是在包含main函数的文件中将tFlag定义为全局变量,并在包含TI1_OnInterrupt函数的文件中将其外部化。你可以在这个link上找到更多关于C变量作用域的信息,也可以在这个link上找到关于存储类的更多信息-- extern就是其中之一。
发布于 2014-11-20 15:43:55
您应该检查函数TI1_OnInterrupt。
这个函数使用一个变量tFlag,搜索这个变量,它在某个地方被声明,如下所示
extern int tFlag;
但是这个定义似乎缺失了。
您需要添加
ìnt tFlag;
从您发布的代码中:
void main(void)
{
bool tFlag = FALSE;
...tFlag变量仅在main()中可见。
您应该将它移到函数之外
发布于 2014-11-20 23:52:48
我相信我这样做是正确的。这是我的源代码,我有。
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.
**
** ###################################################################
*/我觉得我错过了一些简单的东西。感谢您的回复!
https://stackoverflow.com/questions/27031175
复制相似问题