简体   繁体   English

如何解决“函数的隐式声明”

[英]How to fix “ implicit declaration of function”

I'm working on a GUI library in C for a school work, but I've got a problem with header files (I think). 我正在使用C的GUI库进行学校作业,但是头文件存在问题(我认为)。 I have a function "rectangle_coordinates" in a "draw.c" file, with the adequate "draw.h" header file, and in a file "widget_frame.c" I call this function, after including the "draw.h" header file. 我在“ draw.c”文件中有一个函数“ rectangle_coordinates”,带有足够的“ draw.h”头文件,在文件“ widget_frame.c”中,我在包含“ draw.h”头之后调用了此函数文件。 But I still got a warning : 但是我仍然得到警告:

./src/ei_widget_frame.c:40:5: warning: implicit declaration of function 'rectangle_coordinates' [-Wimplicit-function-declaration]
     rectangle_coordinates(&frame_to_draw, &xmin, &xmax, &ymin, &ymax);

Do you have an idea that can fix my problem ? 您有解决我问题的想法吗?

At a minimum, all things below should be verified and corrected (if needed). 至少,应验证和纠正以下所有内容(如果需要)。

  1. The function name must be the same in all places (check for typo's). 函数名称在所有位置都必须相同(检查拼写错误)。
  2. The return type must be the same in all places. 返回类型在所有地方都必须相同。
  3. The parameters list must be the same in all places. 所有地方的参数列表必须相同。

In draw.h you should have something like: draw.h您应该具有以下内容:

extern /type/ rectangle_coordinates(&frame_to_draw, &xmin, &xmax, &ymin, &ymax);

where: 哪里:

  • /type/ is the return type of the function. / type /是函数的返回类型。
  • the parameters list needs to be written correctly (I just made copy / paste from the warning message provided). 参数列表需要正确编写(我只是从提供的警告消息中进行了复制/粘贴)。

In both draw.c and ei_widget_frame.c you should have: draw.cei_widget_frame.c您都应具有:

#include "draw.h"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM