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

Share your advanced PureBasic knowledge/code with the community.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

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

Post 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
Last edited by FloHimself on Fri Sep 09, 2005 1:19 am, edited 1 time in total.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

That is very neat.
@}--`--,-- A rose by any other name ..
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

thanks flohimself. :)
Fred
Administrator
Administrator
Posts: 18253
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

interesting :)
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post 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...)
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Awesome! Thanks for sharing! 8)
Good programmers don't comment their code. It was hard to write, should be hard to read.
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post 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?
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

Whow.... that's tricky :!: Thanks, Flo.
regards,
benny!
-
pe0ple ar3 str4nge!!!
okasvi
Enthusiast
Enthusiast
Posts: 150
Joined: Wed Apr 27, 2005 9:41 pm
Location: Finland

Post by okasvi »

is it possible to place that trick somewhere else than procedure? eg. datasection or something?
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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:)
Good programmers don't comment their code. It was hard to write, should be hard to read.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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.
My favorite numbers: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply