implicit declaration of function 的原因以及解决方法

报错:

在这里插入图片描述

原因:

  1. 没有把函数所在的.c文件生成.o目标文件;
  2. 在函数所在的.c文件中声明了函数,但是没有在与之相关联的.h文件中声明

解决方法:

  1. 在需要调用该函数的文件中声明该函数;
    在这里插入图片描述
  2. 也可在相应.h文件中声明函数
    (不加extern)在这里插入图片描述

结果:

成功解决,两种方法都可以
在这里插入图片描述

  • 6
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
引用\[1\]: $ gcc -g a.c -Werror a.c: In function 'main': a.c:7:10: error: implicit declaration of function 'malloc' \[-Werror=implicit-function-declaration\] 7 | arr = malloc(sizeof(int)); | ^~~~~~ a.c:7:10: error: incompatible implicit declaration of built-in function 'malloc' \[-Werror\] a.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'malloc' 1 | #include <stdio.h> +++ |+#include <stdlib.h> 2 | cc1: all warnings being treated as errors 。 引用\[2\]: 编译报错: $ gcc -g a.c a.c: In function 'main': a.c:7:10: warning: implicit declaration of function 'malloc' \[-Wimplicit-function-declaration\] 7 | arr = malloc(sizeof(int)); | ^~~~~~ a.c:7:10: warning: incompatible implicit declaration of built-in function 'malloc' a.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'malloc' 1 | #include <stdio.h> +++ |+#include <stdlib.h> 问题。 引用\[3\]: 即从gcc -g a.c 升级为 gcc -g a.c -Werror。 $ gcc -g a.c a.c: In function 'main': a.c:7:10: warning: implicit declaration of function 'malloc' \[-Wimplicit-function-declaration\] 7 | arr = malloc(sizeof(int)); | ^~~~~~ a.c:7:10: warning: incompatible implicit declaration of built-in function 'malloc' a.c:2:1: note: include '<stdlib.h>' or provide a declaration of 'malloc' 1 | #include <stdio.h> +++ |+#include <stdlib.h> 2 | 。 问题: implicit declaration of function ‘LLLength’ 回答: 错误信息中的"implicit declaration of function 'LLLength'"表示在代码中使用了一个未声明的函数LLLength。这个错误通常发生在没有包含函数所在的头文件的情况下。要解决这个问题,你需要在代码中包含函数所在的头文件,或者提供函数的声明。 #### 引用[.reference_title] - *1* *2* *3* [为什么告警warning implicit declaration of function必须修复](https://blog.csdn.net/jackgo73/article/details/129496698)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值