Ошибка lnk2001 неразрешенный внешний символ maincrtstartup

I’m learning Assembly at my university, and we were given a CD with MASM 615 on it, and we’re using the Irvine32 include library. Everything works fine with it on the school computer, but when I try to compile and run the same code on my home computer, I get a link error.

INCLUDE Irvine32.inc

.code
main PROC

mov eax,10000h      ; EAX = 10000h
add eax,40000h      ; EAX = 50000h
sub eax,20000h      ; EAX = 30000h
call DumpRegs

exit
main ENDP
END main

This code works fine on the PC at school. At home, I go into DOS, set the path to the MASM folder, and do Make32 file.

This is the error I get:

LINK32 : error LNK2001: unresolved external symbol _mainCRTStartup
test.exe : fatal error LNK1120: 1 unresolved externals

The program compiles (I get the .lst, .obj, and .pdb files), but that’s it. I’m thinking it’s because I have a 64-bit operating system at home, but I have zero idea how to get this up and running in a 64-bit enviornment — the CD or the book has nothing on 64-bit systems. There’s only a make16 or make32 .bat file. It’s a real bummer because that means I can’t do any work at home, unless there’s a work around?

I’m learning Assembly at my university, and we were given a CD with MASM 615 on it, and we’re using the Irvine32 include library. Everything works fine with it on the school computer, but when I try to compile and run the same code on my home computer, I get a link error.

INCLUDE Irvine32.inc

.code
main PROC

mov eax,10000h      ; EAX = 10000h
add eax,40000h      ; EAX = 50000h
sub eax,20000h      ; EAX = 30000h
call DumpRegs

exit
main ENDP
END main

This code works fine on the PC at school. At home, I go into DOS, set the path to the MASM folder, and do Make32 file.

This is the error I get:

LINK32 : error LNK2001: unresolved external symbol _mainCRTStartup
test.exe : fatal error LNK1120: 1 unresolved externals

The program compiles (I get the .lst, .obj, and .pdb files), but that’s it. I’m thinking it’s because I have a 64-bit operating system at home, but I have zero idea how to get this up and running in a 64-bit enviornment — the CD or the book has nothing on 64-bit systems. There’s only a make16 or make32 .bat file. It’s a real bummer because that means I can’t do any work at home, unless there’s a work around?

почему , когда я создаю пустой консольный вин32 и пишу туда самое -простое :

#include <iostream>

int main () {}

выдает ошибку 1>LINK : error LNK2001: неразрешенный внешний символ «_mainCRTStartup» ((((

а стоит создать заголовочный проект вин32 , программа туда добавляет

#include «stdafx.h» и после этого все работает нормально .

Кто может обьяснить ?

До сегодняшнего дня ,я пробывал использовать VC 6.00 1998 года , так там все было норм — все примеры из книжки перепечатывались и работали ) а тут поставил 2010 и ппц. ничего не компилится, пока не включил STDAFX.h

  • Remove From My Forums
  • Question

  • I’m a newbie working through Horton’s Beginning Visual C++.  I’ve been at it for several months.  Last week I got two (related?) errors resuting in a failure to build.

    Horton has us setting Project Properties General Characterset to «Not Set».  We start off with Win32 Console empty project with Precompiled headers.  It has worked fine for months until last week.  I can’t even build a «hello world» 1
    line project in VC++ 2010, now.

    I’ve tried two things I found in the forums:

     1.  Set Character Set to Unicode.  (this eliminates the AlwaysCreate is true error but not the fatal LNK2001→LNK1120 error.  Just to repeat, up until last week this was NOT giving me any problems.

    2.  I also tried adding a manifest validate line to the manifest command line.  No joy.

    Finally, this morning I downloaded and reinstalled Visual Studio in hopes that that would work.  Nope.

    I would appreciate anyone’s ideas on how to solve this.  Win 7 (64bit) Visual Studio 2010 Ver 10.0.30319.1

    1>—— Build started: Project: Test2, Configuration: Debug Win32 ——

    1>Build started 3/13/2011 6:02:05 PM.

    1>InitializeBuildStatus:

    1> Touching «DebugTest2.unsuccessfulbuild».

    1>ManifestResourceCompile:

    1> All outputs are up-to-date.

    1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup

    1>c:usersdaviddocumentsvisual studio 2010ProjectsTest2DebugTest2.exe : fatal error LNK1120: 1 unresolved externals

    1>

    1>Build FAILED.

    • Moved by

      Monday, March 14, 2011 8:46 AM
      move to VC++ forum for better support. (From:Visual Studio Debugger)

Answers

  • Hi,

    According to your description, I think you have a issue about build your C++ project.

    Could you please follow these steps.

    1. Click File menu and choose the Add->project.

    2. Expand the Visual C++ node, select Win32, and click Win32 Console Application (please make sure that you click this option).

    3. Input the name and click on OK.

    4. Make sure that Application type is Console Application , do not change anything, and select Finish.

    5. There is a _tmain function in the cpp file which has the same name with the project.

    6. Build and Start your project or Click F5.

    If your project cannot build or run successfully, please check your configurations of Visual Studio.

    On the other hand  I have followed your steps in my Visual Studio 2010. However it built successfully.  Here is my project and files.

    http://cid-ae2442667686801e.office.live.com/self.aspx/.Documents/T1.rar

    Could you build and run the project in your Visual Studio? If it cannot , maybe there are some  configuration issues in your computer or Visual Studio. 
    Please try to reinstall your windows or Visual Studio. If they still have issue , feel free and let me know.

    Best Regards,

    Rob


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by
      Rob Pan
      Monday, March 21, 2011 2:31 AM

How do I avoid the unresolved external symbol _mainCRTStartup error when using the MSVC toolchain (ex: CL.EXE) from within an MSYS environment?

Details:

I started a «VS2013 x64 Native Tools Command Prompt» and the launched C:msys64msys2.exe from there.

In my MSYS session I get results like this:

user@host MSYS /c/libpostal/libpostal
$ "/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/vcvars64.bat"

user@host MSYS /c/libpostal/libpostal
$ cl "-nologo" "conftest.c" "-link" "-SUBSYSTEM:CONSOLE"
conftest.c
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
conftest.exe : fatal error LNK1120: 1 unresolved externals

user@host MSYS /c/libpostal/libpostal
$ cat conftest.c
/* confdefs.h */
#define PACKAGE_NAME "libpostal"
#define PACKAGE_TARNAME "libpostal"
#define PACKAGE_VERSION "1.0.0"
#define PACKAGE_STRING "libpostal 1.0.0"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_URL ""
#define PACKAGE "libpostal"
#define VERSION "1.0.0"
/* end confdefs.h.  */

int
main ()
{

  ;
  return 0;
}

user@host MSYS /c/libpostal/libpostal
$ echo $PATH
/c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl

If I try to put the same «cl» command into the «VS2013 x64 Native Tools Command Prompt», I get the expected result instead:

C:libpostallibpostal>cl "-nologo" "conftest.c" "-link" "-SUBSYSTEM:CONSOLE"
conftest.c

C:libpostallibpostal>cl "/nologo" "conftest.c" "/link" "/SUBSYSTEM:CONSOLE"
conftest.c

C:libpostallibpostal>conftest.exe

C:libpostallibpostal>echo %PATH%
C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDECommonExtensionsMicrosoftTestWindow;C:Program Files (x86)MSBuild12.0binamd64;C:Program Files (x86)Microsoft Visual Studio 12.0VCBINamd64;C:WindowsMicrosoft.NETFramework64v4.0.30319;C:Program Files (x86)Microsoft Visual Studio 12.0VCVCPackages;C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 12.0Common7Tools;C:Program Files (x86)HTML Help Workshop;C:Program Files (x86)Microsoft Visual Studio 12.0Team ToolsPerformance Toolsx64;C:Program Files (x86)Microsoft Visual Studio 12.0Team ToolsPerformance Tools;C:Program Files (x86)Windows Kits8.1binx64;C:Program Files (x86)Windows Kits8.1binx86;C:Program Files (x86)Microsoft SDKsWindowsv8.1AbinNETFX 4.5.1 Toolsx64;C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDECommonExtensionsMicrosoftTestWindow;C:Program Files (x86)MSBuild12.0binamd64;C:Program Files (x86)Microsoft Visual Studio 12.0VCBINamd64;C:WindowsMicrosoft.NETFramework64v4.0.30319;C:Program Files (x86)Microsoft Visual Studio 12.0VCVCPackages;C:Program Files (x86)Microsoft Visual Studio 12.0Common7IDE;C:Program Files (x86)Microsoft Visual Studio 12.0Common7Tools;C:Program Files (x86)HTML Help Workshop;C:Program Files (x86)Microsoft Visual Studio 12.0Team ToolsPerformance Toolsx64;C:Program Files (x86)Microsoft Visual Studio 12.0Team ToolsPerformance Tools;C:Program Files (x86)Windows Kits8.1binx64;C:Program Files (x86)WindowsKits8.1binx86;C:Program Files (x86)Microsoft SDKsWindowsv8.1AbinNETFX 4.5.1 Toolsx64;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program Files (x86)Microsoft Dynamics AX60ClientBin;C:Program FilesMicrosoft Dynamics AX60BusinessConnectorBin;C:Program Files (x86)Microsoft SQL ServerClient SDKODBC110ToolsBinn;C:Program Files (x86)Microsoft SQL Server120ToolsBinn;C:Program Files (x86)Microsoft SQL Server120DTSBinn;C:Program Files (x86)Microsoft SQL Server120ToolsBinnManagementStudio;C:Program FilesMicrosoftWeb Platform Installer;C:Program Files(x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Files (x86)Windows Kits8.1Windows Performance Toolkit;C:Program Files (x86)Microsoft SDKsTypeScript1.0;C:Program FilesMicrosoft SQL Server120ToolsBinn;C:Program FilesGitcmd;C:Ddmd2windowsbin;C:msys64;C:msys64usrlocalbin;C:msys64usrbin;C:msys64bin;C:msys64optbin

This happened while I was trying to use cccl to build a posix project (libpostal) using the MSVC toolchain so I can link it with other MSVC code. As such, any answers involving Visual Studio GUI will probably not be very helpful: I need to figure out how to make it work from within the MSYS2/MSYS64 environment.

In the MSYS example I intentionally moved /c/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin to the beginning of my $PATH to avoid selecting the wrong executables. I originally received the same results (exact same error message) when it was at the end of the $PATH instead.

  • Ошибка lnk2001 неразрешенный внешний символ main
  • Ошибка lnk1181 не удается открыть входной файл
  • Ошибка lnk1169 обнаружен многократно определенный символ один или более
  • Ошибка lnk1168 не удается открыть exe для записи
  • Ошибка lnk1120 неразрешенных внешних элементов 1