The MASM Forum

Projects => MASM32 => Topic started by: TheGuy on January 21, 2014, 04:46:43 AM

Title: linking lib problem
Post by: TheGuy on January 21, 2014, 04:46:43 AM
I created a .lib with a procedure which I want to use in another masm32 program.

Could someone point me how do I  correctly link and use the library?

MyProc PROTO
include .\include\masm32.inc
includelib .\lib\masm32.lib
INCLUDELIB .\lib\MyLib.lib ; which contains the procudre called MyProc


but when compiling i get error undefined external MyProc.

Title: Re: linking lib problem
Post by: Vortex on January 21, 2014, 05:43:16 AM
Welcome to the forum.

Could you provide the source code of your procedure MyProc? How do you create the static library?
Title: Re: linking lib problem
Post by: TheGuy on January 21, 2014, 06:52:46 AM
.386
.MODEL flat, STDCALL
option casemap:none

MyProc PROTO
include .\include\masm32.inc
includelib .\lib\masm32.lib
INCLUDELIB .\lib\MyLib.lib ;

_DATA segment
_DATA ENDS

_TEXT Segment
MyProc PROC
                 local Var:DWORD
                 mov Var,EAX
       ...
MyProc ENDP

END


.\bin\ml /c /coff  .\%1\%1.asm .\%1\%1.obj
.\BIN\lib /out:./%1.lib ./%1.obj

I did compile everything correcly but still not working as intended.

When  I invoke the procedure  MyProc

invoke MyProc

then in debbugger I can see that the function doesnt even contain a stack frame and the program executes weird instructions like
ADD BYTE PTR DS:[EAX],AL ;access violation error

instead of

mov Var,EAX
Title: Re: linking lib problem
Post by: Vortex on January 21, 2014, 07:12:38 AM
Any specific reason to use segmented directives? Here is an easier version :

include     \masm32\include\masm32rt.inc

.code

MyFunc  PROC x:DWORD,y:DWORD

LOCAL var:DWORD

    mov     eax,x
    mov     var,eax
    mov     eax,y
    add     var,eax
    mov     eax,var
    ret

MyFunc  ENDP

END


include     \masm32\include\masm32rt.inc

includelib  MyLib.lib

MyFunc      PROTO :DWORD,:DWORD

.data

format1     db '90 + 10 = %d',0

.data?

buffer      db 32 dup(?)

.code

start:

    invoke  MyFunc,90,10

    invoke  wsprintf,ADDR buffer,ADDR format1,eax
    invoke  StdOut,ADDR buffer

    invoke  ExitProcess,0

END start


\masm32\bin\ml /c /coff MyFunc.asm
\masm32\bin\ml /c /coff Demo.asm
\masm32\bin\lib /OUT:MyLib.lib MyFunc.obj

\masm32\bin\polink /SUBSYSTEM:CONSOLE Demo.obj


Title: Re: linking lib problem
Post by: TheGuy on January 21, 2014, 07:41:21 AM
Everything is clear now. Thank you.
Title: Re: linking lib problem
Post by: Gunther on January 22, 2014, 01:07:47 AM
Hi TheGuy,

welcome to the Forum.

Gunther