c++visual-studiomfcvisual-studio-2019clang-cl

Missing ATL::CStringT function in MFC/DLL Builds with Clang/VS-2019


Recently installed the new LLVM/clang-cl toolset in Visual Studio 2019, which is a potentially brilliant addition! However, when building my EXE and DLL files, I get the following error at link time:

lld-link : error : undefined symbol: "__declspec(dllimport) public: static void __cdecl ATL::CSimpleStringT<wchar_t, 1>::CopyChars(wchar_t *, unsigned __int64, wchar_t const *, int)" (__imp_?CopyChars@?$CSimpleStringT@_W$00@ATL@@SAXPEA_W_KPEB_WH@Z)

It only happens when building with "Use MFC in a Shared DLL" and in the "Release" configuration: i.e., with either "Use MFC in a Static Library" or in "Debug" configuration, the error disappears.

The 'offending function is defined in the cstringt.h header with the _ATL_INSECURE_DEPRECATE("blah blah") attribute, but re-defining this to 'empty' doesn't fix the problem.

To reproduce, create a default MFC, dialog-based app in VS-2019 with the New Project wizard and add the following in the OnInitDialog() function:

// TODO: Add extra initialization here
    CString txt1 = L"Hello, ";
    CString txt2 = L"world!";
    CString mess = txt1 + txt2;
    SetDlgItemText(IDC_STATIC, mess);

Build as default to check, then switch the "Platform Toolset" to "LLVM (clang-cl)" and rebuild! You'll need to comment-out or disable the manifest-related lines at the end of the generated "framework.h" file:

    #ifndef __clang__
    #ifdef _UNICODE
    #if defined _M_IX86
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    #endif
    #endif

I've tried the following #defines in my global header, but to no avail:

    #define _CRT_SECURE_NO_DEPRECATE
    #define _SECURE_ATL 0
    #define _SECURE_SCL 0
    #define _ATL_INSECURE_DEPRECATE(a)
    #define _ATL_DEBUG_INTERFACES

So: (1) Is this a 'bug' that I should report to Microsoft or am I doing something daft? (2) Can anyone suggest a patch/fix so I can really test my MFC projects with clang? Note: I have to use MFC in a DLL as I rely on extension DLLs.


Solution

  • I have come across the same issue and found that disabling inline function expansion (/Ob0) in the project configuration solves the problem. Did you happen to have it enabled (/Ob1 or /Ob2)?