You receive the linker tools warning "LNK4221" message when you try to add resources to a static library (815773)



The information in this article applies to:

  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++ Standard Edition, version 6.0

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.

MORE INFORMATION

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:
  1. Create, and then build an MFC Application project. To do this, follow these steps:
    1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
    2. On the File menu, point to New, and then click Project
    3. 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++.
    4. In the Name text box, type MyApp, and then click OK.
    5. Click Finish.
    6. Build the MyApp project.
    MyApp.res resource file is created in the debug directory.
  2. Create, and then build a Win32 Project. To do this, follow these steps:
    1. Start Visual Studio .NET or Visual Studio 2005.
    2. On the File menu, point to New, and then click Project
    3. 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++.
    4. In the Name text box, type TestLib, and then click OK.
    5. In the Win32 Application Wizard, click Next, click Application Settings, click Static Library under Application type, and then click Finish.
    6. 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.
    7. In the Add Existing Item dialog box, locate, and then add MyApp.res.
  3. Build the TestLib project. You may receive the warning message that is mentioned in the "Summary" section.
  4. Remove MyApp.res from the TestLib project. Repeat steps f and g in step 2 to add the MyApp.res resource file.
  5. Build the TestLib project. You may receive the warning message that is mentioned in the "Summary" section.
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.

Modification Type:MajorLast Reviewed:1/5/2006
Keywords:kbResource kbCompiler kbinfo KB815773 kbAudDeveloper