Microsoft KB Archive/923418

= FIX: You cannot link a C++ object file that contains MBCS symbols in Visual C++ 2005 =

Article ID: 923418

Article Last Modified on 6/11/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft Visual Studio 2005 Team Edition for Database Professionals
 * Microsoft Visual Studio 2005 Team Edition for Software Architects
 * Microsoft Visual Studio 2005 Team Edition for Software Developers
 * Microsoft Visual Studio 2005 Team Edition for Software Testers

-



SYMPTOMS
In Microsoft Visual C++ .NET 2003, you create an object (.obj) file that contains multibyte character sets (MBCS) symbols. When you try to link the object file in Visual C++ 2005, you receive the following errors in the Output window: error LNK2001: unresolved external symbol fatal error LNK1120: 1 unresolved externals



CAUSE
This behavior occurs because the Visual C++ 2005 linker only supports Unicode. The Visual C++ 2005 linker does not support MBCS string symbols. However, Visual C++ .NET 2003 supports MBCS strings. Therefore, when you use an object file that contains MBCS symbols that were created by Visual C++ .NET 2003, you experience the problem that the &quot;Symptoms&quot; section mentions.



Hotfix information
A supported hotfix is now available from Microsoft. However, it is intended to correct only the problem that is described in this article. Apply it only to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Visual Studio 2005 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Customer Support Services to obtain the hotfix. For a complete list of Microsoft Customer Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites
You must have Visual Studio 2005 Service Pack 1 (SP1) installed to apply this hotfix.

Restart requirement
You do not have to restart the computer after you apply this hotfix.

File information
The Japanese version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.



MORE INFORMATION
If you want to use a symbol that contains an MBCS string in Visual C++ 2005, you may have to do one of the following after you install the hotfix:
 * Set the _LINK_MBCS environment variable.
 * Create a custom .def file that includes an MBCSEXPORTS section.

To determine whether you have to do this when you use the Visual C++ 2005 linker, use the following guidelines for your scenario.

Scenario 1
Consider the following scenario:
 * You build an .exe file or a .dll file that contains .obj files or .lib files that are generated by the Visual C++ 2005 linker.
 * The current application has no dependencies on Visual C++ .NET 2003 DLLs or executable files.
 * The current application does not import or export any APIs that are consumed by an application that was built by using Visual Studio .NET 2003.
 * The current application does not import or export any APIs that are called in an application that was built by using Visual Studio .NET 2003.

In this scenario, you do not have to set the _LINK_MBCS environment variable or use a custom .def file during the build process.

Scenario 2

 * You build an .exe file or a .dll file that contains .obj files or .lib files that are generated by the Visual C++ .NET 2003 linker. The .lib files can be static or dynamic.
 * The current application does not export any APIs that are consumed by an application that was built by using Visual Studio .NET 2003.

In this scenario, you must set the _LINK_MBCS environment variable during the build process. You do not have to use a custom .def file.

Scenario 3

 * You build an .exe file or a .dll file that contains .obj files or .lib files that are generated by the Visual C++ .NET 2003 linker. The .lib files can be static or dynamic.
 * The current application exports an API that is consumed by an application that was built by using Visual Studio .NET 2003.

In this scenario, you must set the _LINK_MBCS environment variable and use a custom .def file during the build process.

Set the _LINK_MBCS environment variable and use a custom .def file
If you have to set the _LINK_MBCS environment variable or use a custom .def file that includes an MBCSEXPORTS section, follow these steps:  To set the environment variable, type the following command at a command prompt, and then press ENTER:

set _LINK_MBCS=1

Note To clear the environment variable, type the following command, and then press ENTER:

set _LINK_MBCS=

  Add an MBCSEXPORTS section to the .def file. The MBCSEXPORTS section should resemble the following:  MBCSEXPORTS Function_name Note  represents the name of the function that contains the MBCS string. 

Keywords: kbhotfixserver kbqfe kbpubtypekc KB923418

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.