I have some compiler / linker errors, and I don’t know what the correct method is to continue. I am in this situation:
Now, if I declare foo1 and foo2 in ah and bh as extern inline void, I got the following error:
prj / src / bo: In the function foo1': (.text+0x0): multiple definition of foo1' prj / src / main.o :(. text + 0x0): first defined here: * [kernel] Error 1
foo1': (.text+0x0): multiple definition of
How can I compile and link without errors / warnings in the described situation?
From http://gcc.gnu.org/onlinedocs/gcc/Inline.html :
If the built-in function is not static, then the compiler must accept that there may be calls from other source files; since a global symbol can be defined only once in any program, the function should not be defined in other source files, so calls to them cannot be integrated. Therefore, a non-static built-in function is always compiled as you wish.
In other words, without static it produces a character for your inline function. If you manage to define this function in the header and include it in several compilations, then you will get several (overridden) characters. If you want to include the definition in the header, you must make it static .
static
Place the inline definitions in your .h file, and create an external definition in the .c files.
inline
.h
.c
For example:
// File: ah inline void foo1(void) { /*...*/ } // File main.c #include "ah" extern inline void foo1(void); int main(void) { /*...*/ }
I tried and did not get errors
hijras
extern inline void foo1() { return; }
bh
extern inline void foo2() { foo1(); return; }
main.cpp
#include "ah" #include "bh" int main() { foo1(); foo2(); return 0; }