0

I'm creating an app to test an api func IsCharLowerA and then output res using MessageBoxA. I'm using masm32.

link /SUBSYSTEM:WINDOWS kod.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

kod.obj : warning LNK4033: converting object format from OMF to COFF
kod.obj : error LNK2001: unresolved external symbol __ExitProcess@4
kod.obj : error LNK2001: unresolved external symbol __MessageBoxA@16
kod.obj : error LNK2001: unresolved external symbol __imp__printf
kod.obj : error LNK2001: unresolved external symbol __imp__scanf
kod.obj : error LNK2001: unresolved external symbol _IsCharLowerA@4
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
ml kod.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: kod.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/z2
"kod.obj"
"kod.exe"
NUL
LINK : warning LNK4044: unrecognized option "z2"; ignored
kod.obj : warning LNK4033: converting object format from OMF to COFF
LINK : fatal error LNK1181: cannot open input file "kod.exe"

I've tried to use microsoft masm32 (to compile code in visual studio), but when the app starts it's only ask for a char and then closes. I could not try to debug due to "source not available" error.

Some code:

.586 
.model flat, stdcall 
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\kernel32.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib 

.data
msg db 'Enter char: ', 0
messagebox_title db ' Лабораторна робота № 5 ', 0
result_0 db ' NOT LOWERCASE ', 0
result_1 db ' LOWERCASE ', 0
scan_modifier db '%c', 0    

.data?
scan_res dd ?

.code
start:  
    push ebp
    mov ebp, esp

    invoke crt_printf, OFFSET msg

    invoke crt_scanf, OFFSET scan_modifier, scan_res

    push scan_res
    call IsCharLowerA

    push 0
    push offset messagebox_title        

    cmp eax, 0
    jne notNULL
    push offset result_0
    jmp next
notNULL:
    push offset result_1
next:
    push 0                           
    call MessageBoxA          

    push 0                        
    call ExitProcess   

    pop ebp
end start

Update #1: (changed MessageBoxA -> MessageBoxA@16 and others)

Code:

.586 
.model flat, stdcall 
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\kernel32.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\kernel32.lib
includelib C:\masm32\lib\user32.lib 

extrn MessageBoxA@16 : PROC
extrn ExitProcess@4 : PROC

.data
msg db 'Enter char: ', 0
messagebox_title db ' Лабораторна робота № 5 ', 0
result_0 db ' NOT LOWERCASE ', 0
result_1 db ' LOWERCASE ', 0
scan_modifier db '%c', 0    

.data?
scan_res dd ?

.code
start:  
    push ebp
    mov ebp, esp

    invoke crt_printf, OFFSET msg

    invoke crt_scanf, OFFSET scan_modifier, scan_res

    push scan_res
    call IsCharLowerA

    push 0
    push offset messagebox_title        

    cmp eax, 0
    jne notNULL
    push offset result_0
    jmp next
notNULL:
    push offset result_1
next:
    push 0                           
    call MessageBoxA@16          

    push 0                        
    call ExitProcess@4   

    pop ebp
end start

Res:

link /SUBSYSTEM:WINDOWS kod.obj
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

kod.obj : warning LNK4033: converting object format from OMF to COFF
kod.obj : error LNK2001: unresolved external symbol _MessageBoxA@16
kod.obj : error LNK2001: unresolved external symbol __imp__printf
kod.obj : error LNK2001: unresolved external symbol _ExitProcess@4
kod.obj : error LNK2001: unresolved external symbol __imp__scanf
kod.obj : error LNK2001: unresolved external symbol _IsCharLowerA@4
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
kod.exe : fatal error LNK1120: 6 unresolved externals

I have a code error LNK2001: unresolved external symbol _MessageBox (uploaded #2 "Final working code") is not succeed linking too

SageCat
  • 315
  • 1
  • 13
  • Looks similar to https://stackoverflow.com/questions/4123013/error-lnk2001-unresolved-external-symbol-messagebox – Joachim Isaksson Nov 10 '19 at 08:30
  • @JoachimIsaksson Nope, it's not. Uploaded result. – SageCat Nov 10 '19 at 08:58
  • Yòu added the `extrn` rows from the example? Either way, can't test myself on this computer so if it doesn't work I'll have to leave it to someone that can :) – Joachim Isaksson Nov 10 '19 at 09:02
  • @JoachimIsaksso Sorry, now the new code is uploaded. – SageCat Nov 10 '19 at 09:07
  • The other question does not use a leading underscore in the symbol names in the `extrn` or calls, that may affect your result. – Joachim Isaksson Nov 10 '19 at 09:13
  • @JoachimIsaksso nothing changed actually. Uploaded to update#1 – SageCat Nov 10 '19 at 09:17
  • I'll see if I have time to test this myself on a computer which can run masm, but for now I can't really help more, sorry. – Joachim Isaksson Nov 10 '19 at 09:26
  • @JoachimIsaksso I have his code https://stackoverflow.com/questions/4123013/error-lnk2001-unresolved-external-symbol-messagebox (uploaded 2 "Final working code") is not succeed linking too, the same: unresoled external symbol for messageboxa and exitprocess – SageCat Nov 10 '19 at 09:28
  • @JoachimIsaksso Oh, everything is fine, do not worry! Thanks for the help) – SageCat Nov 10 '19 at 09:30

1 Answers1

0

The problems was:

  • 1) For scanf needed OFFSET scan_res, because not value is needed.
  • 2) Can not be compiled using both windows and console subsystem. That's why i used only printfs.

  • 3) Was not enough library msvcrt.

  • 4) Сonverting from OMF to COFF could be ignored.

Working code:

.586 
.model flat, stdcall 
option casemap: none 

include C:\masm32\include\windows.inc 
include C:\masm32\include\user32.inc 
include C:\masm32\include\msvcrt.inc

includelib C:\masm32\lib\msvcrt.lib
includelib C:\masm32\lib\user32.lib 

.data
msg db 'Enter char: ', 0
result_0 db ' NOT LOWERCASE ', 0
result_1 db ' LOWERCASE ', 0
scan_modifier db '%c', 0    

.data?
scan_res dd ?

.code
start:  
    mov ebp, esp

    invoke crt_printf, OFFSET msg

    invoke crt_scanf, OFFSET scan_modifier, OFFSET scan_res

    push scan_res
    call IsCharLowerA    

    cmp eax, 0
    jne notNULL
    invoke crt_printf, OFFSET result_0
    jmp next
notNULL:
    invoke crt_printf, OFFSET result_1
next:                                                         
    ret
end start
SageCat
  • 315
  • 1
  • 13