PRB: Unresolved Externals for Inline FunctionsLast reviewed: August 26, 1997Article ID: Q123768 |
The information in this article applies to:
SYMPTOMSCalling an inline function defined in a separate source file generates the following errors in Visual C++ 32-bit Edition, versions 2.x and 4.0:
error LNK2001: unresolved external symbol "<function name>" <filename.exe> : error LNK1120: 1 unresolved externalsThe 32-bit edition of Visual C++ version 1.0 generates these errors:
warning LNK4016: unresolved external symbol "<Classname>::<Functionname>" error LNK1120: 1 unresolved externalsThe 16-bit editions generate this error:
error L2029: '<ClassName>::<FunctionName>' : unresolved externalThe function is declared in a header (.H) file, defined as an inline function in one source (.CPP) file, and called from a second source (.CPP) file.
CAUSEInline functions are not visible outside of the source file where they are defined. The Inline Specifier section in the C++ Language Reference states, "Functions that are declared as inline and that are not class member functions have internal linkage unless otherwise specified." The Inline Class Member Functions section in the C++ Language Reference states, "A class member function defaults to external linkage unless a definition for that function contains the inline specifier." Query on <inline function linkage> in the Books On-line for further information.
RESOLUTIONHere are five possible workarounds:
STATUSThis behavior is by design.
MORE INFORMATION
Sample Code
/* Compile options needed: /Ob1 or /Ob2 */ /* TEST.H */ class ClassA { private: int Var; public: ClassA (); ~ClassA (); }; /* TEST1.CPP */ #include "test.h" void testfunc(void); inline ClassA::ClassA() { Var = 6; }; // Inline function definition ClassA::~ClassA() {} void main(void) { ClassA test1; testfunc(); } /* TEST2.CPP */ #include "test.h" void testfunc(void) { ClassA test2; // This generates an unresolved external error // on the default constructor when linked } |
Additional query words: 8.00 8.00c 9.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |