Author Topic: linking lib problem  (Read 3888 times)

TheGuy

  • Guest
linking lib problem
« 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?

Code: [Select]
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.


Vortex

  • Member
  • *****
  • Posts: 2376
Re: linking lib problem
« Reply #1 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?

TheGuy

  • Guest
Re: linking lib problem
« Reply #2 on: January 21, 2014, 06:52:46 AM »
Code: [Select]
.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

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

Code: [Select]
mov Var,EAX

Vortex

  • Member
  • *****
  • Posts: 2376
Re: linking lib problem
« Reply #3 on: January 21, 2014, 07:12:38 AM »
Any specific reason to use segmented directives? Here is an easier version :

Code: [Select]
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

Code: [Select]
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

Code: [Select]
\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


TheGuy

  • Guest
Re: linking lib problem
« Reply #4 on: January 21, 2014, 07:41:21 AM »
Everything is clear now. Thank you.

Gunther

  • Member
  • *****
  • Posts: 3585
  • Forgive your enemies, but never forget their names
Re: linking lib problem
« Reply #5 on: January 22, 2014, 01:07:47 AM »
Hi TheGuy,

welcome to the Forum.

Gunther
Get your facts first, and then you can distort them.