BullseyeCoverage Up Contents Search

Error LNK2001 or LNK2019 Unresolved Symbol on Inline Function

Symptoms

When building with Microsoft C++ and coverage build enabled, you get error LNK2001 or LNK2019 on a function symbol (that is not a BullseyeCoverage symbol). The error does not occur with coverage build disabled. Your compile settings do not include any optimization option which expands inline functions.

object: error LNK2001: unresolved external symbol "F"
object: error LNK2019: unresolved external symbol "F" referenced in function "G"

Cause

The function F is defined inline, but its definition is not included in the translation unit for the object file mentioned in the error.

You can confirm this as the cause by reproducing the error with Coverage Build disabled and inline function expansion enabled.

Resolution

Remove the inline keyword from the function definition.

More Information

To enable inline function expansion with Visual Studio, select your project, choose menu command Project Properties, navigate to C/C++ Optimization, and set Inline Function Expansion to Any Suitable (/Ob2).

Updated: 10 Sep 2018