• Welcome to Dark Bit Factory & Gravity.
 

Making tiny FB executable programs

Started by Jim, July 09, 2007

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rbz

Challenge Trophies Won:

ninogenio

i followed all above steps and so far so good now im on to the platform sdk will the newer windows sdk work ok? and its over a gigs worth of download!

i already have visual studio so do i still need the platfom sdk?
Challenge Trophies Won:

Jim

Any version of the SDK should do.  Visual Studio will have them in, I think.
Mine are here
C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib

Jim
Challenge Trophies Won:

ninogenio

phew thanks jim they are there!  :) i thought i was going to be on the think end of a huge download.
Challenge Trophies Won:

ninogenio

im getting a linker error now in the form of


C:\Documents and Settings\nino\Desktop\trinity>Fbc.exe -c trinity.Bas

C:\Documents and Settings\nino\Desktop\trinity>\MASM32\BIN\ml /c /coff stub.asm

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: stub.asm

C:\Documents and Settings\nino\Desktop\trinity>crinkler /SUBSYSTEM:WINDOWS /OUT:
trinity.exe /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\
Lib" kernel32.lib user32.lib trinity.o stub.obj
Crinkler 1.0a (Jan  7 2007) (c) 2005-2007 Aske Simon Christensen & Rune Stubbe

Target: trinity.exe
Subsystem type: WINDOWS
Compression mode: FAST
Hash size: 100 MB
Hash tries: 20
Order tries: 0
Transforms: NONE
Replace DLLs: NONE
Range DLLs: NONE

loading:
  kernel32.lib  user32.lib  trinity.o  stub.obj

: fatal error: LNK   0: could not find symbol '_ChoosePixelFormat@8'


C:\Documents and Settings\nino\Desktop\trinity>pause
Press any key to continue . . .


have i missed a lib out?
Challenge Trophies Won:

Jim

You need to add opengl32.lib glu32.lib gdi32.lib to the link.

Jim
Challenge Trophies Won:

ninogenio

doh of course,

cheers jim the best i can get the trinity example to is 1028 bytes thats with rearanging the code and messing around with crinkler.
Challenge Trophies Won:

ninogenio

hey jim i had a little mess about with your example and the best i could get was 1066 but one thing i noticed was streight away it was linking to 1076 bytes so i guess i must be getting slightly better compresion using these switches.

crinkler /SUBSYSTEM:WINDOWS /ORDERTRIES:10000 /HASHTRIES:500 /OUT:trinity.exe /LIBPATH:"C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib" kernel32.lib user32.lib trinity.o stub.obj opengl32.lib glu32.lib gdi32.lib
Challenge Trophies Won:

Shockwave

Thanks Jim for the excellent help as always! K+

I will have to install 1.7 I think. I don't use the laptop anymore for programming so there's no reason not to update any more I guess.
Shockwave ^ Codigos
Challenge Trophies Won:

neumanix

I tried this with a couple of programs, one using tinyptc and one using glfw. On both attempts I get a linker error that says "could not find symbol WinMainCRTStartup".
What am i missing here?!

ninogenio

i think you might have to rework some of the steps to get tinyptc or glfw working with this as it was geard towards aulds 1k ogl framework also remember with this you cant youse any of fbs commands as jim stubbs them off to get tiny fb executables.
Challenge Trophies Won:

neumanix

ok, I solved the problem that I had... I didn't undertand that there has to be a function called "WinMainCRTStartup" in your code.
But now I get other linking errors, some kind of rnd stuff. I guess that's because I used RND which is a freebasic command.
I'll try some more to get the glfw code to work. I'll need a static glfw.lib I guess, gonna try to figure out how to make one :)

ninogenio

yeah the rnd errors are because rnd belongs to freebasic not sure about glfw but ptc stuff should be possible i think.
Challenge Trophies Won:

coderJeff

Here's a trick that makes small exes.  It won't be as small as crinkler,
but it is fairly easy to set-up, and you need no other resources except what's packaged with fbc 0.18.2.

Assume that FreeBASIC is installed at:
C:\FreeBASIC\

and that our "trick" is installed at:
F:\tinyfb\

Create some directories like so:
mkdir F:\tinyfb\
mkdir F:\tinyfb\bin\
mkdir F:\tinyfb\bin\win32\
mkdir F:\tinyfb\lib\
mkdir F:\tinyfb\lib\win32\


Copy two files from C:\FreeBASIC\ to our new directory:
copy C:\FreeBASIC\bin\win32\i386pe.x F:\tinyfb\bin\win32\i386pe.x
copy C:\FreeBASIC\bin\win32\ld.exe F:\tinyfb\bin\win32\ld.exe


Go into F:\tinyfb\lib\win32\ and create some empty object files just to make the fbc.exe command line happy:
F:
cd \tinyfb\lib\win32\
echo REM > crt2.bas
fbc -c crt2.bas
copy crt2.o crtbegin.o
copy crt2.o crtend.o
copy crt2.o fbrt0.o
cd ..\..


Now let's create our example:
'' hello.bas

#include once "windows.bi"

function WinMainCRTStartup cdecl _
  alias "WinMainCRTStartup" () as integer

  Messagebox( 0, "Small EXE example", "Hello", MB_OK )
  return 0

end function


Finally, the last two steps are to compile, then to link our exe:
fbc -c hello.bas
fbc hello.o -s gui -prefix F:\tinyfb -p "C:\FreeBASIC\lib\win32"


The "-prefix F:\tinyfb" option tells fbc where to pick up the extra bits of code.  Since we provided empty object files, no size is added.  The "-p" options tells fbc where to find all the import libs.

For me, this compiles to 2560 bytes. 

I know this is an old-ish thread, but I meant to post something here after I saw this, but never did.

Also, if you are making a Windows App and are planning to use MSVCRT, but want to make sure you don't get any fb-runtime stuff, the fbc command line option '-nodeflibs' was updated not to include 'fbrt0.o'.  Don't know if that's any help, but thought I would mention.


Shockwave

Some good tips there CoderJeff :) Have some good Karma for that and welcome to the forum (I know you have been registered a while, but it's always nice to see people posting, especially good stuff like that!).
Shockwave ^ Codigos
Challenge Trophies Won:

ninogenio

k+ coderjeff,

its great to hear of other ways size can be reduced in fb. nice one!
Challenge Trophies Won:

rain_storm

Okay I finally got this to work (Just Jim's tiny.exe) it is really my first time working with a commandline tool
now I have a question
Is it better to use OpenGL or tinyptc for creating small exe's if all I'm asking from them is to display a buffer of rgb values (like a xor texture or plasma effect)

Challenge Trophies Won:

coderJeff

Thanks Shockware, ninogenio.  Yeah, I lurk in here from time to time.  You guys put out some impressive stuff.  And use FreeBASIC in ways nobody else is even thinking about.  It's always a pleasure to visit.