0

私は 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 ボードを使用しています。アドバイスをいただければ幸いです。

ありがとうございました、

タイラー

4

3 に答える 3

3

C 言語のスコープの概念がありません。あなたが定義した tFlag 変数は、メイン関数のローカル変数です。これはメイン関数のスタック メモリに割り当てられ、メイン関数だけがその名前でそれを見ることができます。この問題を解決するには、メイン関数を含むファイルで tFlag をグローバル変数として定義し、TI1_OnInterrupt 関数を含むファイルでそれを extern する必要があります。C 変数のスコープの詳細については、このリンクを参照してください。また、ストレージ クラス (extern もその 1 つです) については、このリンクを参照してください。

于 2014-11-22T00:16:36.773 に答える
2

関数 TI1_OnInterrupt を調べる必要があります。
この関数は変数 tFlag を使用し、この変数を検索します。次のような場所で宣言されています。
extern int tFlag;

しかし、定義が不足しているようです。
追加する必要があります
ìnt tFlag;

投稿されたコードから:

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

tFlag変数は main() でのみ表示されます。
関数の外に移動する必要があります

于 2014-11-20T07:43:54.820 に答える
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.
**
** ###################################################################
*/

シンプルなものが欠けているような気がします。お返事ありがとうございます!

于 2014-11-20T15:52:47.660 に答える