flat assembler
Message board for the users of flat assembler.

Index > Windows > Creating a static *.lib file for use in VC++

Author
Thread Post new topic Reply to topic
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 23 Mar 2005, 22:23
I have used the search function but the stuff i have found is not working at all. I mean its no problem to create a dll but i can't create a lib ? Is there really no simple way to create a static lib file using fasm?

thx for your time
Post 23 Mar 2005, 22:23
View user's profile Send private message Reply with quote
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 24 Mar 2005, 13:22
Can no one give me a hint or something please?
Post 24 Mar 2005, 13:22
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 24 Mar 2005, 14:07
With MSVC you may use MS COFF format which is supported by FASM.
Post 24 Mar 2005, 14:07
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 24 Mar 2005, 15:11
I would love to use the MS COFF format but I get > 1000 errors if i change

format PE GUI 4.0 DLL

to

format MS COFF

The DLL is over 150kb in size (compiled).
Post 24 Mar 2005, 15:11
View user's profile Send private message Reply with quote
flaith



Joined: 07 Feb 2005
Posts: 122
Location: $300:20 58 FC 60 N 300G => Vietnam
flaith 24 Mar 2005, 15:23
The only way i know to make a lib (.a or .lib) from a DLL is that way:
1st : Must have binutils from mingw (at least PEXPORTS.EXE and DLLTOOL.EXE)
2nd: pexports mydll.dll > mydll.def
3rd: dlltool -d mydll.def -l libmydll.a (or libmydll.lib)
Post 24 Mar 2005, 15:23
View user's profile Send private message Visit poster's website Reply with quote
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 24 Mar 2005, 16:32
thx flaith but that does not create a static lib file.
Post 24 Mar 2005, 16:32
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 24 Mar 2005, 18:05
Where do you get these errors? In VC or FASM or somewhere else? And what these errors are actually about?
Post 24 Mar 2005, 18:05
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 24 Mar 2005, 21:42
I can not even compile the DLL code with the MS COFF flag. This DLL is extrem HUGE. Every time i fix an error i get 3 new ones.
Post 24 Mar 2005, 21:42
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 24 Mar 2005, 21:54
Have you tried to declare all import functions as extrn and all export functions as public?
Post 24 Mar 2005, 21:54
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Jeff Blue



Joined: 23 Mar 2005
Posts: 6
Jeff Blue 25 Mar 2005, 08:37
I have done that but I can't link the *.obj file in VC.

FASM
extrn VirtualFree:dword

VC error
Enforcer error LNK2001: unresolved external symbol VirtualFree

Thats with all extrn functions
Post 25 Mar 2005, 08:37
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 26 Mar 2005, 22:03
Hi Jeff Blue,

Here is a simple demonstration on building and using a simple static library.

The StdOut function to print NULL terminated strings (Original codes from the masm32 package )
Code:
format MS COFF

public  StdOut as '_StdOut@4'
extrn '__imp__GetStdHandle@4' as GetStdHandle:dword
extrn '__imp__WriteFile@20' as WriteFile:dword
extrn '__imp__lstrlenA@4' as lstrlen:dword

Include '%fasminc%\win32a.inc'

section '.code' code readable executable

proc StdOut,lpszText

hOutPut         dd ?
bWritten                dd ?
sl              dd ?
enter
        invoke  GetStdHandle,STD_OUTPUT_HANDLE
        mov             [hOutPut], eax
        invoke  lstrlen,[lpszText]
        mov             [sl],eax
        lea             eax,[bWritten]
        invoke  WriteFile,[hOutPut],[lpszText],[sl],eax,NULL
        mov             eax,[bWritten]
        return

endp
    


The locate function:
Code:
format MS COFF

public locate as '_locate@8'

extrn '__imp__GetStdHandle@4' as GetStdHandle:dword
extrn '__imp__SetConsoleCursorPosition@8' as SetConsoleCursorPosition:dword

Include '%fasminc%\win32a.inc'

section '.code' code readable executable

proc locate,x,y

    _hOutPut  dd ?
    xyVar dd ?
    enter

    invoke GetStdHandle,STD_OUTPUT_HANDLE
    mov [_hOutPut], eax

    mov  ecx,[x]
    mov  eax,[y]
    shl  eax, 16
    mov  ax, cx

    invoke SetConsoleCursorPosition,[_hOutPut],eax

    return

endp
    


The example code using the static library:
Code:
format MS COFF
public _start

Include '%fasminc%\win32a.inc'

extrn '__imp__ExitProcess@4' as ExitProcess:dword
extrn '_StdOut@4' as StdOut:dword
extrn '_locate@8' as locate:dword


section '.data' data readable writeable

msg     db 'Console application',0

section '.code' code readable executable
_start:

        push    esi
        xor     esi,esi
@@:
        inc     esi
        stdcall locate,esi,esi
        stdcall StdOut,msg
        cmp     esi,10
        jne     @b
        pop     esi     
        invoke  ExitProcess,0
    


Building the library and the final executable:
Code:
set fasminc=\fasmw\include
\fasm\fasm StdOut.asm
\fasm\fasm locate.asm
\fasm\fasm Conssamp.asm

\masm32\bin\lib /OUT:console.lib StdOut.obj locate.obj
\masm32\bin\link /SUBSYSTEM:CONSOLE /ENTRY:start /LIBPATH:c:\masm32\lib\ Conssamp.obj console.lib kernel32.lib user32.lib
    


Description:
Download
Filename: staticlib.zip
Filesize: 3.28 KB
Downloaded: 588 Time(s)


_________________
Code it... That's all...
Post 26 Mar 2005, 22:03
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.