This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Weird linker error when inline function is reused in a given C implementation file



Seems like a bug but I'm not sure. I have a first C implementation file with a bunch of functions declared as inline. Every function but one can be reused in a second implementation file. Using that function in the second implementation file results in an unresolved symbol linker error. That function is also used in the first implementation file. If I remove the call from the first implementation file or that I don't declare the function as inline everything is linked properly. As if the compiler was stripping the symbol alltogether if an inline function is used but keeps the symbol if not used in a given implementation file. Is it normal? If so is there a directive to instruct the compiler not to do that? Thanks.

  • Because inline functions are inserted into the code at the place where they are called, the compiler must know the function body. Therefore, it is not possible to use an inline function that is defined in some other .c file.

    It never makes sense to use "inline" without "static". If you want to use an inline function in multiple .c files, you must put not only the declaration but also the definition into a header file.

**Attention** This is a public forum