Page 1 of 2

Pass your options to linker [link to external .obj / .lib]

Posted: Wed Aug 24, 2005 11:11 pm
by FloHimself
hi,

i searched a way to export data from a dll and it took some time to
get this working.
(see here: viewtopic.php?t=16192)

because this is an time consuming way of compiling when testing code,
i searched a better way, a way to pass options to the polink.exe directly.

finally i found a way. all it needs is a patched fasm.exe and now i can
compile my dll from editor without using /COMMENTED & /REASM, just
by adding this to the purebasic source:

Code: Select all

!public v_FunctionTable
!section '.drectve' drectve hidden
!DB '/EXPORT:FunctionTable=v_FunctionTable,DATA '
!section '.text' code readable executable
how this is done? look here: http://board.flatassembler.net/topic.php?t=1590

now, erm, maybe this opens another door? ;)

best regards,
flohimself

Posted: Wed Aug 24, 2005 11:50 pm
by Dare2
That is very neat.

Posted: Thu Aug 25, 2005 3:19 am
by jack
thanks flohimself. :)

Posted: Thu Aug 25, 2005 12:19 pm
by Fred
interesting :)

Posted: Thu Aug 25, 2005 2:34 pm
by okasvi
yep. were interesting indeed :D

Thanks flohimself, ive been reading few days about 400 threads from fasm board(windows section) from the beginning of the board :D still about 450topics to do :D and luckily you have found it :D i guess i would have just passed it as irrelevant and read with eyes closed scrolling fast down...


(my english sucks sry...)

Posted: Fri Sep 09, 2005 1:30 am
by FloHimself
just a notice to myself: ;)

played a bit with Randall Hydes HLA and thought i should try to write a .obj in HLA and link with it in PB.

here we go (what nasty hacks):

Purebasic:

Code: Select all

Procedure dummy()
!extrn _foobar
!section '.drectve' drectve hidden
!DB 'foobar.obj '
!section '.text' code readable executable
EndProcedure

!MOV [v_foobar], _foobar
Debug PeekS(CallFunctionFast(foobar))
and foobar.obj in HLA:

Code: Select all

unit MyUnit;
  procedure foobar; external("_foobar");
  procedure foobar; @nodisplay; @noframe; @noalignstack;
  begin foobar;
    lea( eax, "Hello World" );
    ret();
  end foobar;
end MyUnit;
so, linking to external .obj and .lib files works.

/EDIT: anyone who want to try this at home without recompiling fasm,
can download the precompiled here: http://rzserv2.fhnon.de/~lg016586/downl ... modded.exe

Posted: Fri Sep 09, 2005 7:51 am
by traumatic
Awesome! Thanks for sharing! 8)

Posted: Fri Sep 09, 2005 1:15 pm
by okasvi
WOW :shock:

this is what i tried to do few days ago :twisted:

thank you :D



edit: is that space after obj file needed?

Posted: Fri Sep 09, 2005 3:47 pm
by FloHimself
okasvi wrote:edit: is that space after obj file needed?
it seems to work without spaces, but i don't know if this directive
is inserted before or after the command-line directives from purebasic or
maybe it isn't merged together at all and handled a different way by
linker.

Posted: Fri Sep 09, 2005 6:47 pm
by benny
Whow.... that's tricky :!: Thanks, Flo.

Posted: Sat Sep 10, 2005 3:11 pm
by okasvi
is it possible to place that trick somewhere else than procedure? eg. datasection or something?

Posted: Sat Sep 10, 2005 4:52 pm
by FloHimself
i dont think so.
this could work:

Code: Select all

Goto END_DRCTIVE
!extrn _foobar 
!section '.drectve' drectve hidden 
!DB 'foobar.obj' 
!section '.text' code readable executable 
END_DRCTIVE:
just place in some inlcude file.

Posted: Tue Sep 27, 2005 11:13 am
by traumatic
FloHimself, only wanted to say again this rules! :)

I spent a minute or two and played with libv2:

Code: Select all

!jmp doneInit 
  !extrn _ssInit@8
  !extrn _ssPlay@0
  !extrn _ssGetTime@0
  !extrn _ssClose@0
  
  !section '.drectve' drectve hidden
  !DB 'libv2.lib dsound.lib'
  !section '.text' code readable executable
!doneInit:

ssInit.l    : !MOV [v_ssInit], _ssInit@8
ssPlay.l    : !MOV [v_ssPlay], _ssPlay@0
ssGetTime.l : !MOV [v_ssGetTime], _ssGetTime@0
ssClose.l   : !MOV [v_ssClose], _ssClose@0


tuneadr.l = ?tune
hwnd = GetForegroundWindow_()
!PUSH dword [v_hwnd]
!PUSH dword [v_tuneadr]
!CALL [v_ssInit]

!CALL [v_ssPlay]

time.l
Repeat
  !CALL [v_ssGetTime]
  !MOV [v_time], eax
  Debug time
  Delay(10)
Until GetAsyncKeyState_(#VK_ESCAPE)

!CALL [v_ssClose]

End

DataSection
  tune:
    ;
    ; ...data here...
    ;
EndDataSection
Cool thing! I just couldn't come up with a reason to favour this way
over writing a wrapper lib. :P

(CallFunctionFast() adds 1.5kb! :shock: :lol:)

Posted: Tue Sep 27, 2005 4:23 pm
by FloHimself
nice example traumatic!

sure its easier to do a wrapper-lib. and for sure its easier to handle.
at first i just used this hack to export variables from DLLs and
wanted to let you know that this could even be used to link with
external libs. maybe some other things are possible. fred should
give us way to link to external libs easily. maybe he can include
some new keywords to use this features with "native" PB commands.

Posted: Tue Sep 27, 2005 4:46 pm
by Psychophanta
FloHimself wrote:fred should give us way to link to external libs easily. maybe he can include some new keywords to use this features with "native" PB commands.
Here is one more vote for that :D