> a.h:在此文件中定义了一个声明为“inline”的函数,例如:inline void foo1();
> b.h:在这个文件中定义了一个声明为“inline”的函数,它调用foo1():inline void foo2();
> main.c:foo1和foo2()都有一些函数调用.
现在,如果我在a.h和b.h中声明foo1和foo2作为extern inline void我得到以下错误:
prj/src/b.o: In function
foo1': (.text+0x0):
foo1′
multiple definition of
prj/src/main.o:(.text+0x0): first defined here make: *
[kernel] Error 1
解决方法
When an inline function is not static,then the compiler must assume
that there may be calls from other source files; since a global symbol
can be defined only once in any program,the function must not be
defined in the other source files,so the calls therein cannot be
integrated. Therefore,a non-static inline function is always compiled
on its own in the usual fashion.
换句话说,如果没有静态,它会为您的内联函数发出一个符号.如果您碰巧在标头中定义了该函数并将其包含在多个编译单元中,那么您最终会得到多个(重新定义的)符号.如果要在标题中包含定义,则应将其设置为静态.