gcc warning: function used but not defined

后端 未结 3 1890
鱼传尺愫
鱼传尺愫 2021-02-04 03:13

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 <

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 03:42

    Declare the function normally in the header file

    a.h

    #ifndef A_H_INCLUDED
    #define A_H_INCLUDED
    
    void function1(void);
    
    #endif
    

    Define the function in a single code file with no static

    a.c

    #include "a.h"
    
    void function1(void) {
      /* function definition */
    }
    

    and call the function from other files, after including the header

    b.c

    #include "a.h"
    
    void quux(void) {
      function1(); /* call regular function */
    }
    

    The way you had before (static and implementation in header file) worked because each code file that included that header got its own version of the function; different to every other function of the same name in every other file (but doing exactly the same).

提交回复
热议问题