Search code examples
c++dllwarningslinkage

About inconsistent dll linkage


How can I remove this link warning? You can see code segment that causes this warning.

static AFX_EXTENSION_MODULE GuiCtrlsDLL = { NULL, NULL };
//bla bla
// Exported DLL initialization is run in context of running application
    extern "C" void WINAPI InitGuiCtrlsDLL()
    {
     // create a new CDynLinkLibrary for this app
      new CDynLinkLibrary(GuiCtrlsDLL);
     // nothing more to do
    }

warning C4273: 'InitGuiCtrlsDLL' : inconsistent dll linkage

I have also export and import definitions, like:

#ifdef _GUICTRLS
   #define GUI_CTRLS_EXPORT __declspec(dllexport)
#else
   #define GUI_CTRLS_EXPORT  __declspec(dllimport)
#endif

Solution

  • There are multiple possibilities:

    1) static AFX_EXTENSION_MODULE GuiCtrlsDLL = { NULL, NULL };

    You use AFX_EXTENSION_MODULE. This means that you are implementing an MFC extension DLL. For such extension dlls you have to define the preprocessor _AFXEXT. Set this in the C++ compiler settings of your Visual C++ project

    see:

    How To Use _declspec(dllexport) in an MFC Extension DLL: http://support.microsoft.com/kb/128199

    AFX_EXTENSION_MODULE Structure: http://msdn.microsoft.com/en-us/library/sxfyk0zk.aspx

    TN033: DLL Version of MFC: http://msdn.microsoft.com/en-us/library/hw85e4bb.aspx

    2) It is likely that you have a duplicated definiton/declaration.