You have something completely different from what you need. In the header you should use:
inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); }
In translation units that include this header, this will create an inline function with external linkage. You should also place an ad in one of these translation units:
extern void SPFD54124B_write_cmd(uint16_t);
This (along with the inline definition from the header) will create an external function definition. Other files that contain a header but do not include an extern declaration will create a built-in function definition: the definition is available only in this translation unit, but this does not prohibit an external definition elsewhere.
In total, you will get one external definition of the function, and each file containing the header will also have an external definition; the compiler can use either. It is clear that in the full program there is still only one function called SPFD54124B_write_cmd - for example, if you take the address of a function in several translation units, you should get the same value.
Alternatively, you can put this in the header:
static inline void SPFD54124B_write_cmd(uint16_t command) { spi_write(command, CMD_WIDTH); }
and do not use the extern declaration at all; this will create an inline function with an internal link in each file that includes a header. There will be no external definition of a function, and conceptually, each translation unit that includes a header has its own independent copy of the function.
(For the children it should be noted that the current default mode GCC "gnu89", which does not implement the C99 semantics for inline )
source share