LNK2028 when using /clr:oldSyntax in VS2005

It appears that the error relates to using /clr:pure, but I am not.  The class it is complaining about is in the unmanaged library, and that library is specified in the link options.  It was migrated to and built by VC++ 2005 from the 2003 version.

I don't understand the extern "C" part of the error msg because there is nothing in this class that references any C code - it is all C++.  There is a C code module in the library, but not related to the class CErrorWindow.

This is a Web Service project that compiles and works under VS2003.

The instance of CErrorWindow that is referenced in the code is a global instance that is created by the library code.  It is declared as follows:

#define DllImport __declspec (dllimport)

DllImport CErrorWindow Ew;

And the class declaration looks like this:

class __declspec(dllexport) CErrorWindow : public CStringList {


I really do not understand what's going on here.  Below is the error gibberish.

Thanks, Russ


Error 1 error LNK2028: unresolved token (0A00000A) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" ( ___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "public: __thiscall CErrorWindow::CErrorWindow(void)" ( 0CErrorWindow@@$$FQAE@XZ) PayrollEntryServiceClass.obj 



Answer this question

LNK2028 when using /clr:oldSyntax in VS2005

  • PadamPadam

    I did already forward the link for the post to other memebers of the VC Team.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • John Carter

    Thanks for your post, Russ. I had a similar problem with a VS2003 -> 2005 ported MC++ dll. For me, adding msvcrt.lib msvcmrt.libdid the trick

  • Matt Neerincx

    Ayman, I see that I made a mistake in my last post in that I thought the /NODEFAULTLIB:msvcrt.lib was the same lib as msvcmrt.lib that you suggested.  Never the less, adding msvcmrt.lib did not help because it introduced the error:

    "Error 1 error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagTEXTMETRICA): (0x02000039). msvcmrt.lib"

    My link command line was as follows:

    /OUT:"C:\PssDev\PayrollEntryService\Debug/PayrollEntryService.dll"
    /INCREMENTAL /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"Debug\PayrollEntryService.dll.intermediate.manifest"
    /INCLUDE:"__DllMainCRTStartup@12" /DEBUG /ASSEMBLYDEBUG
    /PDB:"c:\PssDev\PayrollEntryService\Debug\PayrollEntryService.pdb"
    /FIXED:No /ERRORREPORT:PROMPT msvcmrt.lib DLib.lib ClientChecks.lib PsInvlib.lib WebPrint.lib /NODEFAULTLIB:msvcrt.lib

    Any other suggestions

    Thanks, Russ



  • sbrickey

    Nikola, thanks for your suggestion. I had went ahead and used one of my MSDN tech support incidents to get this resolved. One of the things I tried several times to do was remove the include of __DllMainCRTStartup@12, as you just suggested. Every time it resulted in link failures. But eventually we got it all working. So, when I got your message I tried removing it again - now it links fine either with or without that include. One of the things that was happening was that every time I tried to build the web service (after getting it to link) was that VS2005 would tell me it was out of date and needed to be rebuilt - even if it was just built. I finally discovered that removing the /noentry linker option resolved this. Perhaps it also was what finally made the __DllMainCRTStartup@12 include unnecessary.

    Thanks again. This issue is resolved.

    Russ



  • Srinivas Lingineni

    Russk2t wrote:

    /INCLUDE:"__DllMainCRTStartup@12"
    /NODEFAULTLIB:msvcrt.lib

    Try removing both of these and adding msvcrt.lib and mscoree.lib to the list of libraries (keep msvcmrt.lib). I guess that you were following steps described in this KB article for VS2003, http://support.microsoft.com/ id=814472. No need to continue do this anymore. CRT correctly initializes with regard to loader lock.

    Hope this helps,

    Nikola



  • hugh2005

    Ok, but what is the rationale of adding msvcmrt to the link list   In studying the LNK2028 error further I realize that the imortant part is:

    unresolved token (0A00000A) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)"

    So, it is this function, CallUnwindDtor, that is not found, not my class.  Is the msvcmrt library where this function lives

    Also, I have looked again at the long list of errors, and that same LNK2028 error for CallUnwindDtor shows up in many places, including modules that are not mine, such as:

    Error 4 error LNK2028: unresolved token (0A000005) "extern "C" void __clrcall ___CxxCallUnwindDtor(void (__clrcall*)(void *),void *)" ( ___CxxCallUnwindDtor@@$$J0YMXP6MXPAX@Z0@Z) referenced in function "int __stdcall ATL::CompareStringWFake(unsigned long,unsigned long,wchar_t const *,int,wchar_t const *,int)" ( CompareStringWFake@ATL@@$$FYGHKKPB_WH0H@Z) AssemblyInfo.obj

    I did find the following note in the article "How to migrate to /clr":

    "When upgrading a managed library or web service project from Visual C++ 2003 to Visual C++ 2005, the /Zl compiler option will added to the Command Line property page. This will cause LNK2001. Remove /Zl from the Command Line property page to resolve. Or, add msvcrt.lib and msvcmrt.lib to the linker's Additional Dependencies property."

    That last line seems cryptic to me.  It is not clear how adding msvcrt and msvcmrt is related to the use of /Zl.  And for whatever reason, when my project was converted to VS2005, /Zl was not added to the command line.  And msvcrt is specified as /nodefaultlib.  Removing /nodefaultlib from msvcrt causes an error, and adding msvcmrt causes more errors.

    Ayman, you said "may be others on the forum could have more ideas".  It is my experience on these forums that once one person has attempted to answer a question, it is unlikely that others will look at it.  Since you are on the VC++ team, perhaps you could ask another member to have a look at my question.

    Thanks much, Russ



  • Latif1

    Try adding msvcmrt.lib to your link command.

    Thanks,
      Ayman shoukry
      VC++ Team

  • di96rtpn

    Thanks Ayman, but that did not help because I now have errors like:

    Error 1 error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagTEXTMETRICA): (0x02000039). msvcmrt.lib

    But I see that msvcrt is already included in the linker command line as follows:

    /OUT:"C:\PssDev\PayrollEntryService\Debug/PayrollEntryService.dll"
    /INCREMENTAL /NOLOGO /DLL /MANIFEST /MANIFESTFILE:"Debug\PayrollEntryService.dll.intermediate.manifest"
    /INCLUDE:"__DllMainCRTStartup@12" /DEBUG /ASSEMBLYDEBUG
    /PDB:"c:\PssDev\PayrollEntryService\Debug\PayrollEntryService.pdb"
    /FIXED:No /ERRORREPORT:PROMPT DLib.lib ClientChecks.lib PsInvlib.lib WebPrint.lib /NODEFAULTLIB:msvcrt.lib

    Any other suggestions

    Thanks, Russ

  • Wail_gsm

    The only thing that comes to mind is that the packing is different.

    May be others on the forum could have more ideas.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • LNK2028 when using /clr:oldSyntax in VS2005