Unresolved external symbols, despite using include + includelib - both GUI + CLI

Started by sophanox, December 08, 2010, 11:32:05 PM

Previous topic - Next topic

sophanox

Hey guys,

I've spent the past five+ hours looking through google and these forums for an solution to my issue, but to no avail =( - on the plus side everyone here seems to be very helpful and friendly so fingers crossed someone will be able to aid me!

I'm at the very beginning of my windows assembly journey (done a bit of *nix but fancied a change) and I've been following a guide, from which I got this code:


.386
.model flat, stdcall

extrn MessageBoxA016 : PROC
extrn ExitProcess04 : PROC
option casemap :none

include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib


.data 
        helloworld db "hurray for the masm forums!", 0
        MsgTitle db "Our first messagebox", 0
.code
start:

        mov eax, 0
        push eax
        lea ebx, MsgTitle
        push ebx
        lea ebx, helloworld
        push ebx
        push eax
        call MessageBoxA016
        push eax
        call ExitProcess04

end start


In the tutorial, the author includes the libs in the linking via the CLI - i.e.  /libpath:c:\masm32\lib /defaultlib:kernel32.lib /defaultlib:user32.lib but this still produces the same errors as doing it via the GUI:

helloworld.obj : error LNK2001: unresolved external symbol _MessageBoxA016
helloworld.obj : error LNK2001: unresolved external symbol _ExitProcess04
helloworld.exe : fatal error LNK1120: 2 unresolved externals

The paths to the libs are a 100% correct, so I'm not sure why it can't resolve the external processes.

I am using windows 7 64bit

Any help is much appreciated!


jj2007

Why not the standard Masm32 approach?

include \masm32\include\masm32rt.inc

.code
AppName db "Masm32:", 0

start: MsgBox 0, "Hello World", addr AppName, MB_OK
exit

end start


Besides, MessageBoxA016 seems not to be defined in the include files you are using...

sophanox

Thanks for your speedy reply jj2007,

Yeah i've seen other ways of doing it whilst browsing, but the tutorial I'm following does it this way so I was simply following that

The reason behind the 016, according to the author, is that as it takes 4 arguments you need to allocate it 16 bytes.

Removing the 016 gives this error:


error A2005: symbol redefinition : MessageBoxA


I actually just tried your way and it works perfectly jj2007, I thought it must have been an issue with my setup somehow. From now on I'll just use the standard masm32 approach

Thanks a lot!


jj2007

Note MsgBox is a macro that uses MessageBox. The latter is defined in user32.inc as
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox equ <MessageBoxA>


The line
include \masm32\include\masm32rt.inc
includes most standard libraries. Do not use drive letters, i.e. no include C:\masm32\include\masm32rt.inc please; without drive letter, it looks for the file on the drive where your masm32 installation is located - and that makes your code compatible for members who have it on another drive.

sophanox


hutch--

 :bg

Hi sophanox , welcome on board. here is a quick fiddle to fix your code up. The EXTRN syntax has not worked for years, you need the prototypes and libraries. I also added the windows.inc file so you get the standard equates. The code is simple PUSH / CALL notation but on a larger app its viable to use the INVOKE technique from MASM as it makes your code easier to read. On simple code the .386 is OK but unless you are writing code for a very old processor it allows you to use later instructions if you spec a much higher processor.


.686p
.mmx
.xmm



.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc         ; this has the equates
include \masm32\include\user32.inc          ; prototype for MessageBox
include \masm32\include\kernel32.inc        ; prototype for ExitProcess

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


.data
        helloworld db "hurray for the masm forums!", 0
        MsgTitle db "Our first messagebox", 0
.code
start:

    push MB_OK
    push OFFSET MsgTitle
    push OFFSET helloworld
    push 0
    call MessageBox

    push 0
    call ExitProcess

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php