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.
Welcome to the forum.
Could you provide the source code of your procedure MyProc? How do you create the static library?
.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
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
Everything is clear now. Thank you.
Hi TheGuy,
welcome to the Forum.
Gunther