warning:conflicting types for built-in function

本文介绍了在使用arm-linux-gcc编译器时遇到的C标准库函数冲突问题及解决方案。当用户自定义的函数与C标准库中的函数同名时,会导致编译警告。文章提供了两种解决方法:一是更改自定义函数的名称;二是通过编译选项-fno-builtin或-fno-builtin-FUNCTION来禁用内置函数。

在写一些偏底层的应用程序过程中,我们会自己写一些本来已经在C语言标准库里就定义好了的函数,这时候用arm-linux-gcc来编译会出现诸如以下的警告

warning:    conflicting types for built-in function ‘strcpy’

warning:    conflicting types for built-in function ‘puts’

错误原因:

用户自己定义的函数与C标准库产生冲突

解决方法:

1、把自己写的函数改一下名称,以便不冲突

2、在编译的时候加上选项-fno-builtin或-fno-builtin-FUNCTION     

step4/Factorial.c: In function ‘main: step4/Factorial.c:12:9: warning: implicit declaration of function ‘factorial’ [-Wimplicit-function-declaration] factorial(k, current_fact, &fact_len); ^~~~~~~~~ step4/Factorial.c:13:9: warning: implicit declaration of function ‘cumulative’ [-Wimplicit-function-declaration] cumulative(sum, &sum_len, current_fact, fact_len); ^~~~~~~~~~ step4/Factorial.c: At top level: step4/Factorial.c:23:6: warning: conflicting types for ‘cumulative’ void cumulative(int *sum, int *sum_len, int *num, int num_len) ^~~~~~~~~~ step4/Factorial.c:13:9: note: previous implicit declaration of ‘cumulative’ was here cumulative(sum, &sum_len, current_fact, fact_len); ^~~~~~~~~~ step4/Factorial.c: In function ‘cumulative’: step4/Factorial.c:34:5: warning: implicit declaration of function ‘carry’ [-Wimplicit-function-declaration] carry(sum, sum_len); ^~~~~ step4/Factorial.c: At top level: step4/Factorial.c:39:6: warning: conflicting types for ‘factorial’ void factorial(int n, int *result, int *len) ^~~~~~~~~ step4/Factorial.c:12:9: note: previous implicit declaration of ‘factorial’ was here factorial(k, current_fact, &fact_len); ^~~~~~~~~ step4/Factorial.c: In function ‘factorial’: step4/Factorial.c:42:5: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration] memset(result, 0, 40000 * sizeof(int)); ^~~~~~ step4/Factorial.c:42:5: warning: incompatible implicit declaration of built-in function ‘memset’ step4/Factorial.c:42:5: note: include ‘’ or provide a declaration of ‘memset’ step4/Factorial.c: At top level: step4/Factorial.c:57:6: warning: conflicting types for ‘carry’ void carry(int *arr, int *len) ^~~~~ step4/Factorial.c:34:5: note: previous implicit declaration of ‘carry’ was here carry(sum, sum_len); ^~~~~
10-26
a.c: In function ‘CreateGraph’: a.c:38:21: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration] 38 | Graph = (LGraph)malloc( sizeof(struct GNode) ); | ^~~~~~ a.c:2:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’ 1 | #include <stdio.h> +++ |+#include <stdlib.h> 2 | a.c:38:21: warning: incompatible implicit declaration of built-in function ‘malloc’ [-Wbuiltin-declaration-mismatch] 38 | Graph = (LGraph)malloc( sizeof(struct GNode) ); | ^~~~~~ a.c:38:21: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’ a.c: At top level: a.c:93: warning: "MaxVertexNum" redefined 93 | #define MaxVertexNum 1000 | a.c:4: note: this is the location of the previous definition 4 | #define MaxVertexNum 20 /* 最大顶点数设为10 */ | a.c:94:5: error: conflicting types for ‘Visited’; have ‘int[1000]’ 94 | int Visited[MaxVertexNum] = {0}; | ^~~~~~~ a.c:28:6: note: previous declaration of ‘Visited’ with type ‘bool[20]’ 28 | bool Visited[MaxVertexNum]; /* 顶点的访问标记 */ | ^~~~~~~ a.c:98:8: error: redefinition of ‘struct AdjVNode’ 98 | struct AdjVNode{ | ^~~~~~~~ a.c:9:8: note: originally defined here 9 | struct AdjVNode{ | ^~~~~~~~ a.c:104:16: error: redefinition of ‘struct Vnode’ 104 | typedef struct Vnode{ | ^~~~~ a.c:15:16: note: originally defined here 15 | typedef struct Vnode{ | ^~~~~ a.c:106:3: error: conflicting types for ‘AdjList’; have ‘struct Vnode[1000]’ 106 | } AdjList[MaxVertexNum]; | ^~~~~~~ a.c:17:3: note: previous declaration of ‘AdjList’ with type ‘AdjList’ {aka ‘struct Vnode[20]’} 17 | } AdjList[MaxVertexNum]; /* AdjList是邻接表类型 */ | ^~~~~~~ a.c:110:8: error: redefinition of ‘struct GNode’ 110 | struct GNode{ | ^~~~~ a.c:21:8: note: originally defined here 21 | struct GNode{ | ^~~~~ a.c: In function ‘CreateGraph’: a.c:39:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | scanf("%d %d", &Graph->Nv, &Graph->Ne); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.c:47:13: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | scanf("%d", &t); | ^~~~~~~~~~~~~~~ a.c: In function ‘main: a.c:83:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 83 | scanf("%d", &S); | ^~~~~~~~~~~~~~~
最新发布
11-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值