Porting code today encountered a very wonderful problem, recorded as follows:
ERROR[LI006]: Duplicate definitions for "UART3"; In "E:\IAR_1768PRO_PCB799\DEBUG\OBJ\UART3_INIT.O", and "E:\IAR_1768PRO_PCB799\DEBUG\OBJ\UMODEMG600.O"
Repeating defined variables Uart3
However, the umodemg600.c file does not Uart3 this variable, only uart3.h this header file, the problem appears in this file.
Uart3 the definition of this variable is placed in the uart3.h, and uart3.h in uart3.c and UMODEMG600.C have # include, Uart3.h also did not do conditional compilation, resulting in uart3.h repeated compilation, variable repetition definition.
=================== problem description Complete, a personal point of view ======================
My personal practice is that the variables/functions are defined in the *.c file, the variables/functions are declared in the *.h file, and the *.h file is compiled with the condition, and the duplicate inclusions are placed in the following format:
User.c
1 //user.c File2 3#include <stdio.h>4#include <string.h>5#include"User.h"6 7SignedCharG_a =0;8UnsignedCharG_b =0;9SignedintG_c =0;Ten One voidFUN1 (void) A { - //Do something - } the - voidFun2 (void) - { - //Do something +}
User.h
#ifndef _user_h_ #define _user_h_externchar g_a; extern Char G_b; extern int G_c; void fun1 (void); void fun2 (void); #endif
IAR ERROR---[Li006]