c-free出现错误:conflicting types for “ ”时

博客主要分析了C语言中出现 'conflicting types for' 错误的原因。一是未先做函数声明且函数在main()之后,声明函数原型可解决;二是头文件循环引用,需考虑包含顺序;三是头文件声明和定义参数稍有不同也会引发该错误。
常见此类问题的原因如下(引)

错误:
test.c:22: error: conflicting types for 'urlencode'
test.c:18: error: previous implicit declaration of 'urlencode' was here

 

原因一:
原来是因为没有先做函数声明,而函数位于main()之后。
在main函数前声明了函数原型后,一切ok.

 

原因二:

头文件的被循环引用,在引用时考虑清楚包含顺序

 

原因三:

头文件声明和定义参数稍有不同

例:

 头文件中声明 void Hanlder(const char * buf);

 在定义时写作 void Hanlder(char * buf);

这是就会发生conflicting types for 错误问题

转载自:https://blog.youkuaiyun.com/jeakon/article/details/8488965

In file included from src/monitor.c:15:0: src/monitor.h:23:14: error: nested redefinition of 'enum __PRIORITY' typedef enum __PRIORITY ^ src/monitor.h:23:14: error: redeclaration of 'enum __PRIORITY' In file included from <command-line>:0:0: ./src/monitor.h:23:14: note: originally defined here typedef enum __PRIORITY ^ In file included from src/monitor.c:15:0: src/monitor.h:25:5: error: redeclaration of enumerator 'CORE' CORE, ^ In file included from <command-line>:0:0: ./src/monitor.h:25:5: note: previous definition of 'CORE' was here CORE, ^ In file included from src/monitor.c:15:0: src/monitor.h:26:5: error: redeclaration of enumerator 'SECONDARY' SECONDARY, ^ In file included from <command-line>:0:0: ./src/monitor.h:26:5: note: previous definition of 'SECONDARY' was here SECONDARY, ^ In file included from src/monitor.c:15:0: src/monitor.h:27:5: error: redeclaration of enumerator 'AUXILIARY' AUXILIARY ^ In file included from <command-line>:0:0: ./src/monitor.h:27:5: note: previous definition of 'AUXILIARY' was here AUXILIARY ^ In file included from src/monitor.c:15:0: src/monitor.h:30:16: error: redefinition of 'struct __PROCESS' typedef struct __PROCESS ^ In file included from <command-line>:0:0: ./src/monitor.h:30:16: note: originally defined here typedef struct __PROCESS ^ In file included from src/monitor.c:15:0: src/monitor.h:37:3: error: conflicting types for 'PROCESS' } PROCESS; ^ In file included from <command-line>:0:0: ./src/monitor.h:37:3: note: previous declaration of 'PROCESS' was here } PROCESS; ^ In file included from src/monitor.c:15:0: src/monitor.h:39:16: error: conflicting types for 'RecStrat' typedef void (*RecStrat)(PROCESS *p); /* RecoveryStrategy */ ^ In file included from <command-line>:0:0: ./src/monitor.h:39:16: note: previous declaration of 'RecStrat' was here typedef void (*RecStrat)(PROCESS *p); /* RecoveryStrategy */ ^ In file included from src/monitor.c:15:0: src/monitor.h:40:16: error: conflicting types for 'PreStrat' typedef void (*PreStrat)(PROCESS *p); /* PressureStrategy */ ^ In file included from <command-line>:0:0: ./src/monitor.h:40:16: note: previous declaration of 'PreStrat' was here typedef void (*PreStrat)(PROCESS *p); /* PressureStrategy */ ^ In file included from src/monitor.c:15:0: src/monitor.h:42:16: error: redefinition of 'struct __PROCESS_GROUP' typedef struct __PROCESS_GROUP ^ In file included from <command-line>:0:0: ./src/monitor.h:42:16: note: originally defined here typedef struct __PROCESS_GROUP ^ In file included from src/monitor.c:15:0: src/monitor.h:48:3: error: conflicting types for 'PROCESS_GROUP' } PROCESS_GROUP; ^ In file included from <command-line>:0:0: ./src/monitor.h:48:3: note: previous declaration of 'PROCESS_GROUP' was here } PROCESS_GROUP; ^ In file included from src/monitor.c:15:0: src/monitor.h:50:16: error: redefinition of 'struct __PROCESS_MANAGER' typedef struct __PROCESS_MANAGER ^ In file included from <command-line>:0:0: ./src/monitor.h:50:16: note: originally defined here typedef struct __PROCESS_MANAGER ^ In file included from src/monitor.c:15:0: src/monitor.h:55:3: error: conflicting types for 'PROCESS_MANAGER' } PROCESS_MANAGER; ^ In file included from <command-line>:0:0: ./src/monitor.h:55:3: note: previous declaration of 'PROCESS_MANAGER' was here } PROCESS_MANAGER; ^ In file included from src/monitor.c:15:0: src/monitor.h:57:16: error: redefinition of 'struct _ProcessStats' typedef struct _ProcessStats ^ In file included from <command-line>:0:0: ./src/monitor.h:57:16: note: originally defined here typedef struct _ProcessStats ^ In file included from src/monitor.c:15:0: src/monitor.h:66:3: error: conflicting types for 'ProcessStats' } ProcessStats; ^ In file included from <command-line>:0:0: ./src/monitor.h:66:3: note: previous declaration of 'ProcessStats' was here } ProcessStats; ^ In file included from src/monitor.c:15:0: src/monitor.h:68:16: error: redefinition of 'struct _CPUStats' typedef struct _CPUStats ^ In file included from <command-line>:0:0: ./src/monitor.h:68:16: note: originally defined here typedef struct _CPUStats ^ In file included from src/monitor.c:15:0: src/monitor.h:72:3: error: conflicting types for 'CPUStats' } CPUStats; ^ In file included from <command-line>:0:0: ./src/monitor.h:72:3: note: previous declaration of 'CPUStats' was here } CPUStats; ^ In file included from src/monitor.c:15:0: src/monitor.h:76:13: error: conflicting types for 'restart_process' static void restart_process(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:76:13: note: previous declaration of 'restart_process' was here static void restart_process(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:78:12: error: conflicting types for 'check_status' static int check_status(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:78:12: note: previous declaration of 'check_status' was here static int check_status(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:79:21: error: conflicting types for 'get_process_stats' static ProcessStats get_process_stats(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:79:21: note: previous declaration of 'get_process_stats' was here static ProcessStats get_process_stats(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:82:12: error: conflicting types for 'read_cpu_stats' static int read_cpu_stats(CPUStats *stats); ^ In file included from <command-line>:0:0: ./src/monitor.h:82:12: note: previous declaration of 'read_cpu_stats' was here static int read_cpu_stats(CPUStats *stats); ^ In file included from src/monitor.c:15:0: src/monitor.h:84:12: error: conflicting types for 'adjust_oom_score' static int adjust_oom_score(PROCESS *p, int score); ^ In file included from <command-line>:0:0: ./src/monitor.h:84:12: note: previous declaration of 'adjust_oom_score' was here static int adjust_oom_score(PROCESS *p, int score); ^ In file included from src/monitor.c:15:0: src/monitor.h:85:12: error: conflicting types for 'adjust_nice_value' static int adjust_nice_value(PROCESS *p, int value); ^ In file included from <command-line>:0:0: ./src/monitor.h:85:12: note: previous declaration of 'adjust_nice_value' was here static int adjust_nice_value(PROCESS *p, int value); ^ In file included from src/monitor.c:15:0: src/monitor.h:93:13: error: conflicting types for 'core_handle' static void core_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:93:13: note: previous declaration of 'core_handle' was here static void core_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:94:13: error: conflicting types for 'secondary_handle' static void secondary_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:94:13: note: previous declaration of 'secondary_handle' was here static void secondary_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:95:13: error: conflicting types for 'aux_handle' static void aux_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:95:13: note: previous declaration of 'aux_handle' was here static void aux_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:99:13: error: conflicting types for 'core_pressure_handle' static void core_pressure_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:99:13: note: previous declaration of 'core_pressure_handle' was here static void core_pressure_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:100:13: error: conflicting types for 'secondary_pressure_handle' static void secondary_pressure_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:100:13: note: previous declaration of 'secondary_pressure_handle' was here static void secondary_pressure_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:101:13: error: conflicting types for 'aux_pressure_handle' static void aux_pressure_handle(PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:101:13: note: previous declaration of 'aux_pressure_handle' was here static void aux_pressure_handle(PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:104:13: error: conflicting types for 'init_group' static void init_group(PROCESS_GROUP *g, RecStrat R_strategy, PreStrat P_strategy); ^ In file included from <command-line>:0:0: ./src/monitor.h:104:13: note: previous declaration of 'init_group' was here static void init_group(PROCESS_GROUP *g, RecStrat R_strategy, PreStrat P_strategy); ^ In file included from src/monitor.c:15:0: src/monitor.h:105:13: error: conflicting types for 'add_process' static void add_process(PROCESS_GROUP *g, PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:105:13: note: previous declaration of 'add_process' was here static void add_process(PROCESS_GROUP *g, PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:106:13: error: conflicting types for 'remove_process' static void remove_process(PROCESS_GROUP *g, PROCESS *p); ^ In file included from <command-line>:0:0: ./src/monitor.h:106:13: note: previous declaration of 'remove_process' was here static void remove_process(PROCESS_GROUP *g, PROCESS *p); ^ In file included from src/monitor.c:15:0: src/monitor.h:107:13: error: conflicting types for 'monitor_group' static void monitor_group(PROCESS_GROUP *g); ^ In file included from <command-line>:0:0: ./src/monitor.h:107:13: note: previous declaration of 'monitor_group' was here static void monitor_group(PROCESS_GROUP *g); ^ In file included from src/monitor.c:15:0: src/monitor.h:108:13: error: conflicting types for 'resource_pressure_handle' static void resource_pressure_handle(PROCESS_GROUP *g); ^ In file included from <command-line>:0:0: ./src/monitor.h:108:13: note: previous declaration of 'resource_pressure_handle' was here static void resource_pressure_handle(PROCESS_GROUP *g); ^ In file included from src/monitor.c:15:0: src/monitor.h:109:13: error: conflicting types for 'aux_kill' static void aux_kill(PROCESS_GROUP *g); ^ In file included from <command-line>:0:0: ./src/monitor.h:109:13: note: previous declaration of 'aux_kill' was here static void aux_kill(PROCESS_GROUP *g); ^ In file included from src/monitor.c:15:0: src/monitor.h:112:13: error: conflicting types for 'init_manager' static void init_manager(PROCESS_MANAGER *m); ^ In file included from <command-line>:0:0: ./src/monitor.h:112:13: note: previous declaration of 'init_manager' was here static void init_manager(PROCESS_MANAGER *m); ^ In file included from src/monitor.c:15:0: src/monitor.h:113:13: error: conflicting types for 'register_process' static void register_process(PROCESS_MANAGER *m, PROCESS *p, PRIORITY pri); ^ In file included from <command-line>:0:0: ./src/monitor.h:113:13: note: previous declaration of 'register_process' was here static void register_process(PROCESS_MANAGER *m, PROCESS *p, PRIORITY pri); ^ In file included from src/monitor.c:15:0: src/monitor.h:114:13: error: conflicting types for 'check_priority' static void check_priority(PROCESS_MANAGER *m); ^ In file included from <command-line>:0:0: ./src/monitor.h:114:13: note: previous declaration of 'check_priority' was here static void check_priority(PROCESS_MANAGER *m); ^ In file included from src/monitor.c:15:0: src/monitor.h:115:13: error: conflicting types for 'monitor_manager' static void monitor_manager(PROCESS_MANAGER *m); ^ In file included from <command-line>:0:0: ./src/monitor.h:115:13: note: previous declaration of 'monitor_manager' was here static void monitor_manager(PROCESS_MANAGER *m); ^ In file included from src/monitor.c:15:0: src/monitor.h:116:13: error: conflicting types for 'free_manager' static void free_manager(PROCESS_MANAGER *m); ^ In file included from <command-line>:0:0: ./src/monitor.h:116:13: note: previous declaration of 'free_manager' was here static void free_manager(PROCESS_MANAGER *m); ^ src/monitor.c:520:13: error: 'remove_process' defined but not used [-Werror=unused-function] static void remove_process(PROCESS_GROUP *g, PROCESS *p) ^ cc1: all warnings being treated as errors Makefile:15: recipe for target 'monitor.o' failed make[2]: *** [monitor.o] Error 1 make[2]: Leaving directory '/opt/bba/MR500V2_EU1_1/platform/apps/private/user/monitor' Makefile:661: recipe for target 'monitor' failed make[1]: *** [monitor] Error 2 make[1]: Leaving directory '/opt/bba/MR500V2_EU1_1/platform/apps/private/user' /opt/bba/MR500V2_EU1_1/platform/build/makes/Makefile.apps.private:98: recipe for target 'cmm' failed
09-23
In file included from cliTrafficTestHandlers.c:20:0: ../../../../../../../src/application/include/uilib/uilibTrafficTest.h:37:2: error: conflicting types for 'TRAFFIC_TEST_PACKET_CFG' }TRAFFIC_TEST_PACKET_CFG; ^ In file included from ../include/cli_handlers.h:137:0, from ../../../../../../../src/platform/include/h/wrn/wm/cli/cli_common.h:48, from cliTrafficTestHandlers.c:12: ../include/cliTrafficTestHandlers.h:27:2: note: previous declaration of 'TRAFFIC_TEST_PACKET_CFG' was here }TRAFFIC_TEST_PACKET_CFG; ^ cliTrafficTestHandlers.c: In function 'cli_showTrafficTestPacket': cliTrafficTestHandlers.c:140:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->rawPacket, pKey, CFG_TRAFFIC_TEST_F_RAW_PACKET); ^ cliTrafficTestHandlers.c:141:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->srcMac, pKey, CFG_TRAFFIC_TEST_F_SRC_MAC); ^ cliTrafficTestHandlers.c:142:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->dstMac, pKey, CFG_TRAFFIC_TEST_F_DST_MAC); ^ cliTrafficTestHandlers.c:143:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->srcIp, pKey, CFG_TRAFFIC_TEST_F_SRC_IP); ^ cliTrafficTestHandlers.c:144:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->dstIp, pKey, CFG_TRAFFIC_TEST_F_DST_IP); ^ cliTrafficTestHandlers.c:145:60: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->lenType, pKey, CFG_TRAFFIC_TEST_F_LENTYPE); ^ cliTrafficTestHandlers.c:146:59: error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG {aka struct <anonymous>}') tpConfig_IterGetNumU8(&stGetInfo.iterName, &packetCfg->vlan, pKey, CFG_TRAFFIC_TEST_F_VLAN); ^ src/CMakeFiles/cliDev.dir/build.make:1274: recipe for target 'src/CMakeFiles/cliDev.dir/cliTrafficTestHandlers.c.o' failed make[4]: *** [src/CMakeFiles/cliDev.dir/cliTrafficTestHandlers.c.o] Error 1 make[4]: *** Waiting for unfinished jobs.... CMakeFiles/Makefile2:154: recipe for target 'src/CMakeFiles/cliDev.dir/all' failed make[3]: *** [src/CMakeFiles/cliDev.dir/all] Error 2 Makefile:132: recipe for target 'all' failed make[2]: *** [all] Error 2 package/tplink/tplink-generic.mk:289: recipe for target '/project/fep_source_2/buildroot/build/ac5x_pro/build/tplink/cli-1.0/.stamp_built' failed make[1]: *** [/project/fep_source_2/buildroot/build/ac5x_pro/build/tplink/cli-1.0/.stamp_built] Error 2 Makefile:84: recipe for target '_all' failed make: *** [_all] Error 2 要怎么改
最新发布
10-31
<think>我们遇到了两个主要问题: 1. 类型冲突错误:在uilibTrafficTest.h和cliTrafficTestHandlers.h中分别定义了'TRAFFIC_TEST_PACKET_CFG',导致冲突。 2. 结构体成员访问错误:由于类型定义冲突,导致编译器将结构体视为匿名结构,进而无法使用'->'操作符。 解决方案: ### 1. 解决类型冲突 错误信息显示: ``` error: conflicting types for 'TRAFFIC_TEST_PACKET_CFG' }TRAFFIC_TEST_PACKET_CFG; ^ note: previous declaration of 'TRAFFIC_TEST_PACKET_CFG' was here }TRAFFIC_TEST_PACKET_CFG; ``` **原因分析**:同一个类型`TRAFFIC_TEST_PACKET_CFG`在两个不同的头文件中被重复定义,且定义可能不一致。 **修改方案**: - 方案一(推荐):将结构体定义统一到一个公共头文件中,其他文件包含这个头文件。 - 方案二:使用条件编译防止重复定义。 **具体步骤**: (1)创建一个公共头文件,例如`traffic_test_packet_cfg.h`,内容为: ```c #ifndef TRAFFIC_TEST_PACKET_CFG_H #define TRAFFIC_TEST_PACKET_CFG_H typedef struct _TRAFFIC_TEST_PACKET_CFG { char rawPacket[MAX_PAYLOAD_LEN]; char srcMac[MAC_LEN]; char dstMac[MAC_LEN]; char srcIp[IPv4_LEN]; char dstIp[IPv4_LEN]; uint16_t lenType; uint8_t vlan; } TRAFFIC_TEST_PACKET_CFG; #endif ``` (2)删除`uilibTrafficTest.h`和`cliTrafficTestHandlers.h`中的结构体定义,改为包含公共头文件: ```c #include "traffic_test_packet_cfg.h" ``` ### 2. 解决结构体成员访问错误 在统一了结构体定义后,确保在`cliTrafficTestHandlers.c`中正确包含了该公共头文件。然后检查`packetCfg`变量的声明方式。 **错误原因**:之前由于类型冲突,编译器无法识别结构体类型,导致访问成员失败。统一类型定义后,此问题应自然解决。 **注意**:如果`packetCfg`是指针,则使用`->`访问成员;如果是结构体实例,则使用`.`访问。根据错误信息中的`packetCfg->rawPacket`,我们推断`packetCfg`应声明为指针。请确保它被正确初始化为指向有效的结构体内存。 ### 修改后的代码示例 在`cliTrafficTestHandlers.c`中: ```c // 包含公共头文件 #include "traffic_test_packet_cfg.h" void cli_showTrafficTestPacket(...) { // 假设packetCfg是指针 TRAFFIC_TEST_PACKET_CFG *packetCfg = malloc(sizeof(TRAFFIC_TEST_PACKET_CFG)); // ... 其他代码 // 访问成员(正确) tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg->rawPacket, pKey, CFG_TRAFFIC_TEST_F_RAW_PACKET); // ... 其他成员访问 } ``` ### 其他注意事项 - **头文件保护**:确保所有自定义头文件都有`#ifndef`或`#pragma once`防止多重包含。 - **依赖管理**:检查`MAX_PAYLOAD_LEN`、`MAC_LEN`等宏是否在公共头文件或包含的其他头文件中定义。 §§相关问题§§ 1. 在C语言项目中如何有效避免多个头文件之间的类型定义冲突? 2. 使用条件编译防止头文件重复包含的原理是什么? 3. 结构体指针和结构体实例在成员访问上有何区别?什么情况下会导致访问错误? 4. 如何设计跨模块共享的数据结构以保持一致性? 5. 在大型C项目中,有哪些工具或方法可以检测重复的类型定义? </think>### 错误分析与完整解决方案 #### 核心问题诊断: 1. **类型定义冲突**: ``` error: conflicting types for 'TRAFFIC_TEST_PACKET_CFG' note: previous declaration of 'TRAFFIC_TEST_PACKET_CFG' was here ``` - 同一结构体在两个头文件中有不同定义: - `uilibTrafficTest.h` (包含自第20行) - `cliTrafficTestHandlers.h` (包含自第12行) 2. **结构体访问错误**: ``` error: invalid type argument of '->' (have 'TRAFFIC_TEST_PACKET_CFG') ``` - 类型冲突导致编译器无法识别结构体成员 ### 完整修改方案: #### 步骤1:统一结构体定义 在公共头文件中定义统一的结构体类型: ```c // 创建公共头文件 traffic_test_common.h #ifndef TRAFFIC_TEST_COMMON_H #define TRAFFIC_TEST_COMMON_H #include <stdint.h> typedef struct _TRAFFIC_TEST_PACKET_CFG { char rawPacket[512]; // 实际长度根据需求调整 uint8_t srcMac[6]; uint8_t dstMac[6]; uint8_t srcIp[4]; uint8_t dstIp[4]; uint16_t lenType; uint8_t vlan; } TRAFFIC_TEST_PACKET_CFG; #endif // TRAFFIC_TEST_COMMON_H ``` #### 步骤2:修改冲突的头文件 1. 修改 `uilibTrafficTest.h`: ```diff // 删除原有定义 - typedef struct { - ... - } TRAFFIC_TEST_PACKET_CFG; // 添加包含 + #include "traffic_test_common.h" ``` 2. 修改 `cliTrafficTestHandlers.h`: ```diff // 删除原有定义 - typedef struct { - ... - } TRAFFIC_TEST_PACKET_CFG; // 添加包含 + #include "traffic_test_common.h" ``` #### 步骤3:修复成员访问问题 在 `cliTrafficTestHandlers.c` 中: ```c // 确保包含公共头文件 #include "traffic_test_common.h" void cli_showTrafficTestPacket(...) { // 正确声明结构体变量 TRAFFIC_TEST_PACKET_CFG packetCfg; // 正确访问成员(使用点运算符) tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg.rawPacket, pKey, CFG_TRAFFIC_TEST_F_RAW_PACKET); tpConfig_IterGetStrPtr(&stGetInfo.iterName, &packetCfg.srcMac, pKey, CFG_TRAFFIC_TEST_F_SRC_MAC); // ...其他成员同理 } ``` #### 步骤4:清理编译缓存 执行以下命令清除旧编译结果: ```bash make clean # 清理构建产物 rm -rf CMakeCache.txt # 删除CMake缓存 ``` ### 预防措施: 1. **单一真实源原则**: - 公共数据类型只在专门的头文件中定义一次 - 其他地方通过包含使用 2. **头文件保护**: ```c #ifndef UNIQUE_HEADER_NAME #define UNIQUE_HEADER_NAME // 内容 #endif ``` 3. **前向声明优化**: ```c // 在不需要完整定义的地方 typedef struct _TRAFFIC_TEST_PACKET_CFG TRAFFIC_TEST_PACKET_CFG; ``` 4. **依赖管理**: ```cmake # 在CMakeLists.txt中明确定义依赖 target_include_directories(cliDev PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/common ) ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值