gcc警告:函数已使用但未定义 [英] gcc warning: function used but not defined

查看:311
本文介绍了gcc警告:函数已使用但未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到警告:函数已使用但未定义。我的头文件中有 static
__inline __
a.h 。头文件包含在 a.c 中。我想将头文件中的所有内联函数放入 .c 文件中。以下代码给出了我的问题的想法。

I am getting the warning: function used but not defined. I have static __inline__ in header file say a.h. The header file is included in a.c. I would like put all those inline function which are in header files into the .c files. Following code gives the idea of my problem.

原始代码:

ah:

static __inline__ function1(){
    function definition;  
}

我更改了:

ah:

I changed:
a.h:

static function1();

ac:

#include "a.h"

static function1(){
   function definition;
}

在执行上述操作时,我得到了警告:

On doing above I got the warning:

   warning: function function1 is used but not defined. 

能否让我知道为什么我收到这样的警告?我想将所有 __ inline __ 函数转移到 .c 中,这样我就不会收到警告: / p>

Could you please let me know why i am getting such warning? I would like to transfer all the __inline__ function into the .c so that I won't get the warning:

  warning: function1 is could not be inlined, code size may grow.

预先感谢

推荐答案

您已将该函数声明为静态的。这意味着它仅在当前编译单元中可见。换句话说:该实现仅在 a.c 文件内部可见。您需要同时删除 ah ac static 关键字c>,以便其他.c文件可以看到该功能。您应该指定一个返回值,例如 void function1(); ,因为如果未指定,则隐式为 int

You've declared the function to be static. This means that it is only visible within the current compilation unit. In other words: the implementation is only visible inside the a.c file. You need to remove the static keyword both in the a.h and a.c so that other .c files can see the function. You should specify a return value, e.g. void function1(); because it implicitly is int if you didn't specify one.

这篇关于gcc警告:函数已使用但未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆