Linker Tools Warning LNK4049

locally defined symbol 'symbol' imported

The symbol was both exported from and imported to the program.

This warning is generated by the linker when you declare a symbol by using the __declspec(dllexport) storage-class attribute in one object file and reference it by using the __declspec(dllimport) attribute in another.

Warning LNK4049 is a more general version of Linker Tools Warning LNK4217. The linker generates Warning LNK4049 when it cannot determine from which function the imported symbol was referenced.

The common cases where LNK4049 is generated instead of LNK4217 are:

  • Performing incremental linking by using the /INCREMENTAL option.

  • Performing whole-program optimization by using the /LTCG option.

To resolve LNK4049, try one of the following:

  • Remove the __declspec(dllimport) name declaration from the forward declaration of the symbol which triggered LNK4049. You can search for symbols within a binary image by using the DUMPBIN utility. The DUMPBIN/SYMBOLS switch displays the COFF symbol table of the image. For more information on the DUMPBIN utility, see DUMPBIN Reference.

  • Temporarily disable incremental linking and whole-program optimization. Recompiling the application will generate Warning LNK4217, which will include the name of the function from which the imported symbol was referenced. Remove the __declspec(dllimport) declaration from the imported symbol and enable incremental linking or whole-program optimization as required.

Although the final generated code will behave correctly, the code generated to call the imported function is less efficient than calling the function directly. This warning will not appear when you compile by using the option /clr.

For more information on import and export data declarations, see dllexport, dllimport.


Linking the following two modules will generate LNK4049. The first module generates an object file containing a single exported function.

// LNK4049a.cpp
// compile with: /c

__declspec(dllexport) int func() 
   return 3;

The second module generates an object file containing a forward declaration to the function exported in the first module, along with a call to this function inside the main function. Linking this module with the first module will generate LNK4049. Removing the __declspec(dllimport) declaration will resolve the warning.

// LNK4049b.cpp
// compile with: /link /WX /LTCG LNK4049a.obj
// LNK4049 expected

__declspec(dllimport) int func();
// try the following line instead
// int func();

int main()
   return func();

See Also


Linker Tools Warning LNK4217

dllexport, dllimport