我创建了一个ATL工程,加入了一些代码,编译时得到如下错误信息: 
    Linking... 
     Creating library ReleaseMinSize/mail.lib and object ReleaseMinSize/mail.exp 
    LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main 
    不知是何原因,请指教!

解决方案 »

  1.   

    我在MSDN找了一下
    When you build a project of one of these types Win32 console application project
    Active Template Library (ATL) DLL/EXE project with release configuration
    A project with main as custom entry point
    you may get the following error message from linker: 
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main CAUSE
    A Win32 console application requires the main function as the entry point. Linker returns this error message when it cannot find the main function in any of the files attached to the project.If your project is an ATL project, the release configurations for ATL projects define _ATL_MIN_CRT, which excludes CRT (C runtime) startup code from your .exe or .dll file. Linker gives this error message when you have _ATL_MIN_CRT defined and you are using the CRT functions that need CRT startup code.If the project is not one of the types listed in the "Symptoms" section of this article, but you are still getting the error, you might have main selected as an entry point symbol for the project in linker settings but have not provided a main function in the files added to the project. RESOLUTIONIf you have created a Win32 console application instead of a Win32 application by mistake, there are two ways to fix this problem:
    From the Project menu, choose Settings, click the C/C++ tab, and change preprocessor definitions from WIN32, _DEBUG, _CONSOLE, and _MBCS to WIN32, _DEBUG, and _WINDOWS. Next, click the Link tab, and under Project Options, change /subsystem:console to /subsystem:windows. -or-
    Create a new project and select Win32 Application instead of Win32 Console Application. Add the files to that project.
    If you have created a Win32 console application and forgot to provide a main function, write a main function in one of the source files added to the project.
    If you have selected main as the custom entry point by mistake, from the Project menu, choose Settings and click the Linker tab. Select output as the category and remove main from the entry-point symbol text box.
    If your project is an ATL project, there are two ways to fix the problem:
    Remove _ATL_MIN_CRT from the list of preprocessor definitions to allow CRT startup code to be included: From the Build menu, choose Settings. Hold down the CTRL key while selecting all of the release configurations. On the C/C++ tab, choose the General category, and then remove _ATL_MIN_CRT from the preprocessor definitions edit box.-or-
    If possible, remove calls to CRT functions that require CRT startup code and use their Win32 equivalents. For example, use lstrcmp instead of strcmp. Known functions that require CRT startup code include the string and floating point functions.
      

  2.   

    你肯定在程序中使用了一些标准的C语言函数,如mem*函数。如果你想知道到底是哪个函数,可以在工程设置的ignore libraries中输入Libcmt.lib。再次链接时,会报告一些函数找不到,你就可以知道是哪些函数了。如果这些函数是必须的,解决的办法就是从工程设置中删除_ATL_MIN_CRT。
      

  3.   

    哦,行了,谢谢stavck(关未明) 。