i have a static library which (among other things) implements a tiny function that only returns some string from a table of const strings. This function is not called anywhere inside the library, but still it’s declared as inline. For clarity, it looks like this:
namespace flow
{
inline const char* GetName( BYTE methodType );
}
and the implementation:
const char* flow::GetName( BYTE methodType )
{
if ( methodType < 5 )
return cszNameTable[ methodType ];
return NULL;
}
In another project, i’m linking against this library. I have the correct .h files included and I have the using namespace flow; in my code. The problem is, I’m getting linker errors:
error LNK2001: unresolved external symbol "char const * __cdecl flow::GetName(unsigned char)" (?GetName@flow@@YAPBDE@Z)
Now i can easily fix this by removing the “inline” keyword from the function declaration in the static library. So here are my questions:
1) Why does this error appear? How can i fix it without modifying the static library source code (without removing the inline keyword)?
2) What is the benefit of using the inline keyword in a static library function that is not called inside the library itself? Does the inline keyword have any effect when linking against the library from another project (i guess it does, but i’m not sure)?
There’s no point in declaring functions as
inline. You have to define them in the header anyway:The effect of
inlineis that you can, and have to, define the function within the header, because the implementation of aninlinefunction has to be visible where that function is called.