Microsoft KB Archive/815773

= You receive the linker tools warning &quot;LNK4221&quot; message when you try to add resources to a static library =

Article ID: 815773

Article Last Modified on 1/5/2006

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-





SUMMARY
This article discusses the Linker Tools Warning LNK4221 message. This warning occurs when you try to add resources to a static library. The linker tries to add resources in a publicly accessible way. However, the linker fails and you receive the following warning message:

warning LNK4221: no public symbols found; archive member will be inaccessible

An object file was added to an archive library that has no public symbols. The object is not accessible by using subsequent linker commands.



Steps to Reproduce the Behavior
Create, and then build an MFC Single-Document Interface (SDI) or a Multiple-Document Interface (MDI), and also a dialog-based application by using the Application Wizard. To do this, follow these steps:  Create, and then build an MFC Application project. To do this, follow these steps:  Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project Click Visual C++ Projects under Project Types, and then click MFC Application under Templates.

Note In Visual Studio 2005, Visual C++ Projects is changed to Visual C++. In the Name text box, type MyApp, and then click OK. Click Finish. Build the MyApp project.</li></ol>

MyApp.res resource file is created in the debug directory.</li> Create, and then build a Win32 Project. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> Start Visual Studio .NET or Visual Studio 2005.</li> On the File menu, point to New, and then click Project</li> Click Visual C++ Projects under Project Types, and then click Win32 Project under Templates.

Note In Visual Studio 2005, Visual C++ Projects is changed to Visual C++.</li> In the Name text box, type TestLib, and then click OK.</li> In the Win32 Application Wizard, click Next, click Application Settings, click Static Library under Application type, and then click Finish.</li> In Solution Explorer, right-click TestLib, point to Add, and then click Add Existing Item.

Note In Visual Studio 2005, Add Existing Item is changed to Existing Item.</li> In the Add Existing Item dialog box, locate, and then add MyApp.res.</li></ol> </li> Build the TestLib project. You may receive the warning message that is mentioned in the &quot;Summary&quot; section.</li> Remove MyApp.res from the TestLib project. Repeat steps f and g in step 2 to add the MyApp.res resource file.</li> Build the TestLib project. You may receive the warning message that is mentioned in the &quot;Summary&quot; section.</li></ol>

When you put the object file in the archive library, the object file is not included in the final image file. This behavior occurs because the object file does not have public symbols.

Note When you want to share the resources, put the resources in a DLL.

Keywords: kbinfo kbresource kbcompiler KB815773

-

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

© Microsoft Corporation. All rights reserved.