Linker Tools Warning LNK4049
symbol 'symbol' defined in 'filename.obj' is imported
__declspec(dllimport) was specified for symbol even though the symbol is defined in object file filename.obj in the same image. Remove the __declspec(dllimport)
modifier to resolve this warning.
Remarks
This warning is generated by the linker when you define a symbol in one object file and reference it by using the __declspec(dllimport)
declaration modifier in another.
Warning LNK4049 is a more general version of Linker Tools Warning LNK4217. The linker generates warning LNK4049 when it can't determine which function or object file referenced the imported symbol.
The common cases where LNK4049 is generated instead of LNK4217 are:
When using the /INCREMENTAL option.
When using the /LTCG option.
To resolve LNK4049, try one of the following procedures:
Remove the
__declspec(dllimport)
modifier from the forward declaration of the symbol that 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. When recompiled, the application generates Warning LNK4217, which includes the name of the function that references the imported symbol. Remove the
__declspec(dllimport)
declaration modifier from the imported symbol and re-enable incremental linking or whole-program optimization as required.
Although the final generated code behaves correctly, the code generated to call the imported function is less efficient than calling the function directly. This warning doesn't appear when you compile by using the /clr option.
For more information on import and export data declarations, see dllexport, dllimport.
Example
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. Remove the __declspec(dllimport)
modifier from the declaration to 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
Linker Tools Warning LNK4286
dllexport, dllimport