News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

What is "Error LNK2001: unresolved external symbol _WinMainCRTStartup"?

Started by Yollaguay, September 05, 2015, 01:45:02 PM

Previous topic - Next topic

Yollaguay

I'm compiling an asm file and I'm getting this one error but I don't know how to fix it. What causes this error to happen? When I try to "Build All" in MASM32 I get this error, and when I try to "Console Build All", I get "_MainCRTStartup". How do I fix this? Or just general information about this error, because the asm file is too large for me to post it here.

hutch--

You will need to show us the code you are trying to build. It will need to have the correct entry point and be able to access any required libraries.

dedndave

i think that's the error you get if you don't reference the entry point in the END statement

    .CODE

main    PROC

    INVOKE  ExitProcess,0

main    ENDP

    END     main

Yollaguay

I figured it out. I just added "_WinMainCRStartup" to the end of the code and it compiled successfully.

Vortex

Hi Yollaguay,

No need to add _WinMainCRStartup to your code. Let me try to explain it with a quick example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib

.data

message     db 'Messagebox example',0
caption     db 'Hello',0

.code

entry:

    invoke  MessageBox,0,ADDR message,ADDR caption,MB_OK
         
    invoke  ExitProcess,0

END


Building the project :

\masm32\bin\ml /c /coff MsgBox.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: MsgBox.asm

***********
ASCII build
***********

\masm32\bin\polink /SUBSYSTEM:WINDOWS MsgBox.obj
POLINK: error: Unresolved external symbol '__WinMainCRTStartup'.
POLINK: fatal error: 1 unresolved external(s).


The linker complains because the entry point is missing. It should be defined just after the END statement :

.
.
.code

entry:

    invoke  MessageBox,0,ADDR message,ADDR caption,MB_OK
         
    invoke  ExitProcess,0

END entry


END entry tells to the linker that the entry point of the application is the label named entry.  The traditional label to specify the entry point is named as start. You can select another one just like in the example above.

.code

start:

    invoke  MessageBox,0,ADDR message,ADDR caption,MB_OK
         
    invoke  ExitProcess,0

END start