Q: I have a function defined in file A as inline int myfunc().
This function is used in several other functions in the same file and also in four other
files. All files are in a self-contained library with global optimizations enabled. The
linker produces an error message which states that there is an unresolved symbol
_myfunc that is being referenced from the 4 other files. If I look at the.obj file the
function __myfunc is not listed. It seems like the compiler has stripped it out. When I
remove the inline keyword, the project compiles correctly. Also if I use the #pragma
inline instruction it also works correctly. What is going on?
A: The frontend compiler is stripping out the inline function after it inlines them. If you do not want to change your code, the option is to use the –Xcfe -inline off option which disables inlining in the frontend and icode performs the inlining afterwards. The cleanest solution for the user though is to write an inline function in a header file and to include the header file where the inline function is called.