LNK 2001 unresolved external symbol _mainCRTStartup MASM
Asked Answered
L

5

7

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?

Lapse answered 12/9, 2012 at 0:38 Comment(3)
The program Assembles and Links NOT compiles. You do not compile anything when using Assembly. Can you post the make file you are using?Stearic
Sounds like it's not finding the 'doze equivalent to libc. Do the "set" command to view environment variables. Look for the "LIB" variable. Compare what you see at school and at home. You may need to install a C compiler (at home) to get a C library. The missing variable is in your "C startup code" - the code that calls "_main". Might just need to set the "LIB" variable...Liable
The question is not answerable without the "Make32 file".Calceolaria
T
19

The other answers were confusing to me so I'll add my solution. In the properties of the project go to

Configuration Properties >> Linker >> Advanced

In Advanced at the top should be Entry Point. Type in main.

Thirty answered 27/2, 2016 at 19:1 Comment(1)
I can confirm that this is the answer. As a side note: it works for nasm as well.Matelote
C
7

I think you may need to specify the entry point manualy since the default symbol for entry on windows isnt _main but the _mainCRTStartup one from your error message. You can specify entry point with /ENTRY:entry_point (some procedure in your assembly) in your linker options.

Chiropractor answered 12/9, 2012 at 15:8 Comment(4)
The link above appears to be broken.Epitaph
I'm still a bit confused: how would you specify the entry point in the assembly language source code?Epitaph
The link was added by someone else, I have nothing to do with it. The entry point is to be specified as commandline parameter to linker, not in the code.Chiropractor
this was my issue but it will look like ml64.exe myfile.asm /link /entry:myentrypoint (or whatever your assembler .exe is).Gladine
A
3

I know its a bit late - maybe it helps someone - but you should expose main as public, like this

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

PUBLIC main

END 

Note the second last line

Automatize answered 27/7, 2013 at 15:0 Comment(0)
L
1

try to include this

includelib  \Irvine\Irvine32.lib
includelib  \Irvine\User32.lib
includelib  \Irvine\kernel32.lib
Literator answered 30/7, 2015 at 2:37 Comment(0)
R
0

If you use MASM32, add /coff parameter.

Example:

ml.exe /c /coff file.asm
Ricebird answered 20/5, 2022 at 23:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.