Share via


Error LNK2019 / error LNK2001: unresolved external symbol Linker errors for Device projects that use MFC and ATL libraries

Hi, I am Gangadhar, a developer in Visual Studio for Devices. In my
blog posts I will be dealing with issues related to VSD for Native
programming.

 Some of you might have hit linker errors while compiling your device projects that use ATL/MFC libraries.

 

Let me start by explaining why you are seeing these errors in the first
place - the new CE C++ compiler comes with an option of treating
wchar_t as a built in type. The earlier compiler type defined all
wchar_t as unsigned short. When the compiler generated the mangled name
for the wchar_t type appearing in function signatures, it used the
unsigned short type.

The latest compiler comes with an option where one can choose to switch
to use wchar_t as a "built in type" and "not a built in type" (in which
case it is treated as unsigned short type). When you create new
projects using Visual Studio 2005 all the projects using ATL/MFC gets
generated with the new option where the switch "treat wchar_t as built
in type" is turned on by default. Even the ATL/MFC libraries for
devices that are shipped with the latest Visual Studio release are
built with this switch enabled.

The mangled name that gets generated when the wchar_t type is treated
as "built in type" and "not a built in type" are different hence you
will see linker errors when you try to link to ATL/MFC libraries for
devices.

You will be seeing linker errors if you have done one of the following

1. You have created a new C++ MFC smart device project and changed the

    Project -> Properties -> C/C++ -> Language -> "Treat wchar_t as built in type"

    to "No (/Zc:wchar_t-)"

2. You have migrated an eVC project to visual Studio 2005, which links
to some dependent ATL/MFC DLLs which are compiled using previous
versions (like eVC3.0, eVC 4.0 or Visual Studio 2003).

3. You have migrated you eVC ATL/MFC project to Visual Studio 2005 that has no dependent DLLs, but the

    Project -> Properties -> C/C++ -> Language
-> "Treat wchar_t as built in type" is set to "No (/Zc:wchar_t-)"

If you are facing any of these issues in linking to ATL/MFC libraries
then the work around to get through this problem is to rebuild all you
dependent DLLs and the project with the switch turned on, i.e. by
setting the option "Treat wchar_t as built in type" to "Yes" and
rebuilding all the DLLs and projects.

However we are looking at fixing this issue in the next release of Visual Studio.

- Gangadhar Heralgi