The MASM Forum

Miscellaneous => Irvine Book Questions. => Topic started by: lbwiley on June 14, 2019, 01:17:34 AM

Title: Error I'm getting in assembler
Post by: lbwiley on June 14, 2019, 01:17:34 AM
Errors I'm getting: LoganWileyproj3.obj : error LNK2001: unresolved external symbol _ExitProcess@4
LoganWileyproj3.exe : fatal error LNK1120: 1 unresolved externals

Tried a few things
Here's my code:
; LoganWileyproj3.asm - calculated the expression A = (A+B)-(C+D)
INCLUDE Irvine32.inc

.386
.model flat, stdcall
.stack 4096
ExitProcess proto, dwExitCode: dword
.code
main PROC
    ;assign the integer value to registers
    mov eax,150       ; A=EAX=150
    mov ebx,100        ; B=EBX=100
    mov ecx,50          ; C=ECX=50
    mov edx,40         ; D=EDX=40
    ; calculates the expression
    add eax,ebx         ; EAX= (A+B)
    add ecx,edx         ; ECX= (C+D)
    sub eax,ecx         ; EAX= (A+B) - (C+D)
    invoke ExitProcess,0
main ENDP
END MAIN
Title: Re: Error I'm getting in assembler
Post by: jj2007 on June 14, 2019, 01:53:03 AM
Try to remove the comma after proto
Title: Re: Error I'm getting in assembler
Post by: lbwiley on June 14, 2019, 02:27:02 AM
Removing the comma didn't do anything still getting the same error.
Title: Re: Error I'm getting in assembler
Post by: tenkey on June 14, 2019, 02:57:04 AM
The linker is not finding kernel32.lib, which is where _ExitProcess@4 resides.
From your coding style, you will need to add kernel32.lib to the list of files the linker needs. You will need the full path name, unless the LIB environment variable is set properly to the .lib directory. The full pathname will depend on your Irvine configuration.
Title: Re: Error I'm getting in assembler
Post by: jj2007 on June 14, 2019, 04:47:29 AM
This works:
.stack 4096
includelib \masm32\lib\Kernel32.lib
Title: Re: Error I'm getting in assembler
Post by: lbwiley on June 14, 2019, 06:55:43 AM
Thank you
Title: Re: Error I'm getting in assembler
Post by: jj2007 on June 14, 2019, 07:25:54 AM
Sorry for my previous advice. The PROTO does indeed not need a comma, i.e. the normal syntax is someproc PROTO :DWORD, but that was not the problem. As tenkey wrote, it was the missing Kernel32.lib, which can be included either via includelib:
includelib \masm32\lib\Kernel32.lib
or by adding \masm32\lib\Kernel32.lib to the linker's commandline.

Btw if you have any intention to learn assembly seriously, dump Irvine and use the Masm32 SDK (http://www.jj2007.eu/Masm32_Tips_Tricks_and_Traps.htm).
Title: Re: Error I'm getting in assembler
Post by: aw27 on June 14, 2019, 07:36:39 PM
Irvine is not that bad, it teaches how to use Visual Studio with ASM and has a few interesting code samples.
It provides also a kernel32.lib and everything is freely downloadable.

It is always good to know what we are talking about before criticizing.