编译Android内核遇隐式函数声明错误,导入对应头文件仍报错
编译Android内核时的函数隐式声明错误
报错信息
../drivers/interconnect/qcom/msm8916.c:310:9: error: implicit declaration of function 'qnoc_probe' [-Werror,-Wimplicit-function-declaration] return qnoc_probe(pdev, sizeof(msm8916_bus_clocks), ^ ../drivers/interconnect/qcom/msm8916.c:324:12: error: use of undeclared identifier 'qnoc_remove'; did you mean 'idr_remove'? .remove = qnoc_remove, ^~~~~~~~~~~ idr_remove ../include/linux/idr.h:118:7: note: 'idr_remove' declared here void *idr_remove(struct idr *, unsigned long id); ^ ../drivers/interconnect/qcom/msm8916.c:324:12: error: incompatible pointer types initializing 'int (*)(struct platform_device *)' with an expression of type 'void *(struct idr *, unsigned long)' [-Werror,-Wincompatible-pointer-types] .remove = qnoc_remove, ^~~~~~~~~~~ 3 errors generated.
问题背景
编译Android内核时触发上述错误,已在msm8916.c中包含头文件:
#include "icc-rpm.h"
且icc-rpm.h中确实有qnoc_probe的声明:
int qnoc_probe(struct platform_device *pdev, size_t cd_size, int cd_num, const struct clk_bulk_data *cd);
可能的原因及解决方法
头文件保护宏异常
检查icc-rpm.h是否配置了正确的头文件保护宏(如#ifndef ICC_RPM_H、#define ICC_RPM_H、#endif),如果宏缺失或重名,会导致头文件内容未被正确解析。内核编译配置未启用相关模块
确认内核配置中是否开启了QNOC相关编译开关(比如CONFIG_INTERCONNECT_QCOM_QNOC),若该模块被设为n或未配置,函数声明可能被编译条件(如#ifdef)包裹,导致编译时无法识别。头文件路径未被正确识别
检查编译参数中的头文件搜索路径,确认icc-rpm.h所在目录是否被加入-I参数中。路径错误会导致编译器找不到该头文件,无法读取函数声明。函数声明被编译条件限制
查看icc-rpm.h中qnoc_probe和qnoc_remove的声明是否被#ifdef类条件编译语句包裹,若当前编译环境不满足条件(如内核版本、平台不匹配),声明会被隐藏。函数声明或调用存在不匹配
核对msm8916.c中qnoc_probe的调用参数数量、类型是否与头文件声明完全一致;同时确认qnoc_remove是否在icc-rpm.h中有有效声明——当前报错显示该函数未被识别,大概率是声明缺失或被条件编译隐藏。
内容的提问来源于stack exchange,提问作者Seth
相关产品推荐
相关产品推荐

