Article ID: 309801 - View products that this article applies to.
This article was previously published under Q309801
Note Microsoft Visual C++ 2005, Microsoft Visual C++ .NET 2003, and Microsoft Visual C++ .NET 2002 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code.
When you build a Visual C++ 2005 or Visual C++ .NET application that uses a CString-derived class from a DLL file, you may receive an error message that is similar to one of the following:
ClientProject error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(char const *)" (__imp_??0?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@PBD@Z) referenced in function _main
ClientProject error LNK2005: "public: __thiscall ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>::~CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char>>>(void)" (??1?$CStringT@DV?$StrTraitMFC@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@QAE@XZ) already defined in Simple.obj
ClientProject fatal error LNK1169: one or more multiply defined symbols found
This behavior may occur if you use a class derived from CString that is also exported from a DLL.
In Microsoft Visual Studio 2005 or in Microsoft Visual Studio .NET, the CString class has changed to a template class, as demonstrated by the following lines of code taken from afxstr.h:
Visual Studio automatically exports the appropriate template instantiation for the CStringT template class that you derive from. However, when you import the class, Visual Studio .NET sometimes does not correctly import that instantiation. This results in the linker error messages listed in the "Symptoms" section of this article.
To resolve this issue, explicitly import the template class for CStringT and CSimpleStringT in the precompiled header (stdafx.h) file, as follows:
Steps to Reproduce the Problem
Contact us for more help
Connect with Answer Desk for expert help.