Microsoft KB Archive/43646

= INFO: What Causes the Startup Code to Be Included =

Article ID: 43646

Article Last Modified on 12/12/2003

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft C Professional Development System 6.0

 Microsoft C Professional Development System 6.0a

 Microsoft C Professional Development System 6.0a

 Microsoft C/C++ Professional Development System 7.0</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 1.5 Professional Edition</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ 6.0 Service Pack 5</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q43646

<div class="notice_section">

<div class="summary_section">

SUMMARY
The object modules created by the Microsoft C Compiler versions 5.1 and earlier contain a reference to the variable _acrtused. This variable causes the linker to bring in the C startup code. To not link the C startup code, it is necessary to define _acrtused as follows: int _acrtused = 0; Object modules created with the Microsoft C Compiler for MS-DOS, version 6.0, 6.0a, or 6.0ax only have a reference to the _acrtused variable if the source file contains a function called main. In addition, C/C++ versions 7.0 and 8.0 for MS-DOS generate the reference for files containing a WinMain or LibMain function.

For 32-bit targets, __acrtused is not used. Instead, the linker must be told what entry point name to use. The Visual C++ for Windows NT linker picks the name based on the executable type. With the Windows Software Development Kit (SDK) linker, the correct entry point must be specified in the makefile or on the command line. The three entry points are: <pre class="fixed_text">  Executable Type     Entry Point     Entry Point Name Console            main          _mainCRTStartup Windows            WinMain       _WinMainCRTStartup DLL                DllMain       _DllMainCRTStartup@12

<div class="moreinformation_section">

MORE INFORMATION
With Visual C++ 2.x and above, if a DLL project specifies an entry point and attempts to call a CRT function, the linker issues error LNK2001 because it is looking for main. To successfully link the DLL, remove the project setting for entry point. As mentioned in the SUMMARY, _DllMainCRTStartup is the correct entry point.

Additional query words: MFC AFXDLL AFXEXT extension acrtused kbvc100 kbvc150 kbvc1.51 kbvc152 kbvc200 kbvc210 kbvc400 kbvc500 kbvc600

Keywords: kbinfo kbcrt KB43646

-

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

© Microsoft Corporation. All rights reserved.