error LNK2001: unresolved external symbol

Arvind picture Arvind · Feb 16, 2011 · Viewed 19.9k times · Source

I am converting my project from vc6 to VS 2010.When I compile my project i get error as below for may .lib inputs. I have added all these lib in the Linker-> Input-> Additional Dependencies, also provided the path of these .lib files in Link->General->Additional Library directories. Any tip on this will be very helpful.

lb0.lib(ob0.obj) :error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb1.lib(ob1.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb2.lib(ob2.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb3.lib(ob3.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb3.lib(ob4.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb3.lib(ob5.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)
lb4.lib(0b6.obj) : error LNK2001: unresolved external symbol "void __stdcall SetLastExP(class ExceptionClass *)" (?SetLastExP@@YGXPAVExceptionClass@@@Z)

Thanks

Answer

harper picture harper · Feb 23, 2011

You need to identify where the SetLastExP() function is defined.

  • Check that the library that implements SetLastExP is linked.
  • Get the .obj file and check with dumpbin if it implements in the decoration that you expect.

    dumpbin /symbols foo.obj | find "External" | find "SetLastExP"
    
  • Compare the decoration you see with the decoration you have in the Linker error message.

Probably the function is defined as extern "C" while your header file doesn't reflect this.