转自:https://blog.csdn.net/u010650845/article/details/69571892
/*
** ver: 2.52
** file: uCOS_II.C
** brief: C文件集合
*/
#define OS_GLOBALS /* 声明全局变量 防止重复定义 */
#include "includes.h" /* 包含"includes.h"头文件 */
#define OS_MASTER_FILE /* 防止以下文件重复定义宏OS_GLOBALS和重复包含"includes.h" */
#include "\software\ucos-ii\source\os_core.c" /* 包含 "os_core.c" 文件 */
#include "\software\ucos-ii\source\os_flag.c" /* 包含 "os_flag.c" 文件 */
#include "\software\ucos-ii\source\os_mbox.c" /* 包含 "os_mbox.c" 文件 */
#include "\software\ucos-ii\source\os_mem.c" /* 包含 "os_mem.c" 文件 */
#include "\software\ucos-ii\source\os_mutex.c" /* 包含 "os_mutex.c" 文件 */
#include "\software\ucos-ii\source\os_q.c" /* 包含 "os_q.c" 文件 */
#include "\software\ucos-ii\source\os_sem.c" /* 包含 "os_sem.c" 文件 */
#include "\software\ucos-ii\source\os_task.c" /* 包含 "os_task.c" 文件 */
#include "\software\ucos-ii\source\os_time.c" /* 包含 "os_time.c" 文件 */
1. OS_GLOBALS栗子
ucos_ii.h文件有如下定义:
. . .
#ifdef OS_GLOBALS
#define OS_EXT
#else
#define OS_EXT extern
#endif
. . .
OS_EXT INT32U OSCtxSwCtr;
. . .
includes.h文件中有如下定义:
#include "ucos_ii.h"
os_core.c文件有如下定义:
. . .
#define OS_GLOBALS
#include "includes.h"
. . .
因为os_core.c中定义了OS_GLOBALS这个宏,所以OS_EXT宏为空,即os_core.c文件编译结果如下
INT32U OSCtxSwCtr;
结果是在文件os_core.c中定义变量OSCtxSwCtr,其他.c文件不会定义宏OS_GLOBALS,所以OS_EXT的值为extern,即其他.c文件编译时结果如下:
extern INT32U OSCtxSwCtr;
结果是在其他.c中声明变量,因为变量已经定义过了呀呀呀!
2. uCOS_II.C文件
说明:如果你的工程中添加了uCOS_II.C文件,则不要添加该文件下包含的那些C文件否则会出现重复定义错误,如果添加了各C文件则不要添加uCOS_II.C文件,这个故事告诉我们老婆与小三不能兼得【羞涩】