none
How to deal with LNK4248 and C4747 warnings resulting from CLR compilation ?

    Question

  •  

    Hi,

     

    We have an MFC Application that outputs a DLL. We need to make it .NET compatible and hence we need to compile it using /clr option. Once compiled using /clr in VS 2005 we got lot of Linker Errors and Warnings. We have overcomed Linker Errors, but now we are facing some Potential Linker warnings and runtime issues.

     

    Warnings given by CLR compiled code are listed falls under these broad categories: (Total 70 warnings)

    1. warning LNK4099: missing mfcm80u.i386.pdb File. 
    2. warning LNK 4248:
      1. warning LNK4248: unresolved typeref token (01000012) for '_TREEITEM'; image may not run
      2. warning LNK4248: unresolved typeref token (0100001C) for '_IMAGELIST'; image may not run
      3. warning LNK4248: unresolved typeref token (01000019) for 'xercesc_2_7.XMLGrammarPool'; image may not run
    3. warning C4747: Calling managed '_DllMain@12': Managed code may not be run under loader lock, including the DLL entrypoint and calls reached from the DLL entrypoint
    4. warning C4793: 'virtual-call thunks are native with /clr' : causes native code generation for function 'CSWDocumentEvents::`vcall'{112}''              

     

    Can you provide some solution to these warnings Specially warning LNK 4248 and warning C4747

     

    Also I had gone through the link : http://msdn2.microsoft.com/en-us/library/ms235211.aspx

    which speaks about the Compiling MFC extension Dll with CLR.

     

    Thanks

     

    Wednesday, February 13, 2008 6:06 AM

Answers

  • HI~

    I hope these page will help.

     LNK4099 : http://msdn2.microsoft.com/en-us/library/b7whw3f3(VS.80).aspx

     LNK4248 :http://msdn2.microsoft.com/en-us/library/h8027ys9(VS.80).aspx

    And the others will be found easily.

     

    Good Luck~

    Bye~

    Wednesday, February 13, 2008 7:25 AM
  • I did a C++/CLI project using xalan and xerces a while ago. I don't remember which of the two was the root of the issue, but ultimately the problem was that one of them flagged /Zc:wchar_t- and typedef'd wchar_t as unsigned short. This caused linking errors when it came time to use them from a managed project, because under /clr, wchar_t is always __wchar_t, so the mangled names didn't match. So from what I recall, the solution was to alter xalan and/or xerces so they used native wchar_t (__wchar_t) instead of unsigned short.

     

    Sorry I don't have more info for you, this was over a year ago now and I don't remember exactly...

    Wednesday, February 13, 2008 5:30 PM

All replies

  • HI~

    I hope these page will help.

     LNK4099 : http://msdn2.microsoft.com/en-us/library/b7whw3f3(VS.80).aspx

     LNK4248 :http://msdn2.microsoft.com/en-us/library/h8027ys9(VS.80).aspx

    And the others will be found easily.

     

    Good Luck~

    Bye~

    Wednesday, February 13, 2008 7:25 AM
  • Thanks for your prompt reply.

     

    I have gone through those links. It says , for LNK 4248 :

    To correct this error

    • Provide the type definition in the MSIL module.

    I do not know how to provide type definition  for cases like, strcutures or classes defined in commctrl.h and other third Party library.

     

    I need to know if there is any properties settings or any code snippet for such cases which can be used to resolve this issue.

     

    Thanks.

    -Moiz

    Wednesday, February 13, 2008 8:50 AM
  • I did a C++/CLI project using xalan and xerces a while ago. I don't remember which of the two was the root of the issue, but ultimately the problem was that one of them flagged /Zc:wchar_t- and typedef'd wchar_t as unsigned short. This caused linking errors when it came time to use them from a managed project, because under /clr, wchar_t is always __wchar_t, so the mangled names didn't match. So from what I recall, the solution was to alter xalan and/or xerces so they used native wchar_t (__wchar_t) instead of unsigned short.

     

    Sorry I don't have more info for you, this was over a year ago now and I don't remember exactly...

    Wednesday, February 13, 2008 5:30 PM
  • Hi,

     

    resolution for wanring LNK 4248:

    1.       Adding commctrl.h , _TREEITEM and _IMAGELIST definition in stdafx.h of respective modules

    Example: struct _TREEITEM {}; struct _IMAGELIST {};

     

    resolution for warning C4747 :

    Search for initialization Code and follow the steps on each file executed during initialization of DLL:

    1.       Inserted #pragma unmanaged directive above each functionBody in the File

    2.       File properties Changed to No Common Language runtime support

    3.       Removed Precompiled Header --> Not Using Precompiled Headers

     

    regards:

    Moiz

    • Proposed as answer by azzwin Wednesday, August 05, 2009 12:02 PM
    Wednesday, February 27, 2008 10:07 AM
  • Hi,

     

    resolution for wanring LNK 4248:

    1.       Adding commctrl.h , _TREEITEM and _IMAGELIST definition in stdafx.h of respective modules

    Example: struct _TREEITEM {}; struct _IMAGELIST {};

     

    resolution for warning C4747 :

    Search for initialization Code and follow the steps on each file executed during initialization of DLL:

    1.       Inserted #pragma unmanaged directive above each functionBody in the File

    2.       File properties Changed to No Common Language runtime support

    3.       Removed Precompiled Header --> Not Using Precompiled Headers

     

    regards:

    Moiz

    This Tipp is the perfect Solution for this Problem thanks :)
    Wednesday, April 15, 2009 1:09 PM