changelog.txt:
???Version 1.09.0
[added]
- fbc: add '-entry name' command line option to set program entry point (TeeEmCee)
Difference with the '-map < name >' command line ?
???Version 1.09.0
[added]
- fbc: add '-entry name' command line option to set program entry point (TeeEmCee)
Syntax for specifying the entry point:SARG wrote:Entry point : it's a point in a program where the execution of a program begins, and where the program has access to command line arguments.
But the use still obscure.fbc: Add -entry commandline option to override the name of the entry …
…procedure.
This is necessary in order to use SDL 1.2 or SDL 2.0 on at least Android, OSX,
iOS, and winRT, and is optional on Windows. SDL_main.h #defines main to SDL_main,
and declares the real main() itself. Under FB that can't be done, so the solution
is to pass -entry SDL_main when compiling the main module.
No guarentees that that is all that is needed to properly initialise a
FB program under SDL.
Note: I wasn't sure where to put this global. env.clopt.entry would seem to
be the natural place, but env.clopt contains only integral datatypes,
and file-scope for other structures like fbc seems to be strictly enforced.
So it went into fbc and then passed to fbInit and put in env.
It's a compilation option.fxm wrote:'-entry name':
New command-line to add in the 'Compilation' group or rather in the 'Linking' group ?
Code: Select all
'' main1.bas:
'' - simple program
'' - If compiling and linking in separate steps we need to specify
'' which module is the main module.
''
'' compile: $ fbc -c -m main1 main1.bas
'' link : $ fbc main1.o
'' OR
'' compile: $ fbc main1.bas
'' ---------------------------------
'' START OF USER'S IMPLICIT MAIN
'' - internally this procedure is named "main"
'' - a public symbol of "main" is needed to satisfy the linker
'' and run-time system start-up code
print "hello"
'' END OF USER'S IMPLICIT MAIN
'' ---------------------------------
Code: Select all
'' main2.bas
'' - demonstrate internals of a simple program
'' - we must compile and link in separate steps or give a non-existant
'' module name so that fbc doesn't generate the implicit user main
''
'' compile: $ fbc -c main2.bas
'' link : $ fbc main2.o
'' OR
'' compile: $ fbc -m none main2.bas
enum FB_LANG
FB_LANG_INVALID = -1
FB_LANG_FB = 0
FB_LANG_FB_DEPRECATED
FB_LANG_FB_FBLITE
FB_LANG_QB
end enum
'' in the fbc compiler the value of FB_LANG is known
'' in source, we need to reconstruct it from __FB_LANG__
#if __FB_LANG__ = "fb"
const FB_LANG_INDEX = FB_LANG_FB
#elseif __FB_LANG__ = "deprecated"
const FB_LANG_INDEX = FB_LANG_DEPRECTATED
#elseif __FB_LANG__ = "fblite"
const FB_LANG_INDEX = FB_LANG_FBLITE
#elseif __FB_LANG__ = "qb"
const FB_LANG_INDEX = FB_LANG_QB
#else
const FB_LANG_INDEX = FB_LANG_INVALID
#endif
'' Implicitly declared by fbc compiler
'' declare sub fb___main cdecl alias "__main" ()
'' declare sub fb_Init alias "fb_Init" ( byval argc as long, byval argv as zstring ptr ptr, byval lang as long )
'' declare function fb_End alias "fb_End" ( byval code as long ) as long
'' There must be exactly one "main" in the program
'' fbc implicitly defines "main"
function main cdecl alias "main" _
( _
byval argc as long, _
byval argv as zstring ptr ptr _
) as long
'' !!!TODO!!! - dont't assume stack alignment
'' - need to modify the prolog code
'' - fbc takes care of this when this is implicitly generated
'' return value is automatically set to 0 by default, so we don't need this
'' function = 0
#if PROFILING
'' there is no built-in to determine if fbc has profiling enabled
'' call __monstartup()
#endif
#ifdef __FB_WIN32__
fb___main() '' set-up and call global ctors
#endif
fb_Init( argc, argv, FB_LANG_INDEX )
'' all initialization complete, continue with user's 'main'
'' ---------------------------------
'' START OF USER'S IMPLICIT MAIN
print "hello"
'' END OF USER'S IMPLICIT MAIN
'' ---------------------------------
'' return the return code from fb_End()
fb_End( 0 )
'' return value is 0 which has already been set by default
'' but we get a warning here because fbc doesn't know it's already set
end function
Code: Select all
'' main3.bas
'' - demostrate the internals of a simple program with an alternate entry point
'' - we must compile and link in separate steps or give a non-existant
'' module name so that fbc doesn't generate the implicit user main
''
'' compile: $ fbc -c main3.bas -entry custom_main
'' link : $ fbc main3.o
'' OR
'' compile: $ fbc -m none main3.bas -entry custom_main
function custom_main cdecl alias "custom_main" _
( _
byval argc as long, _
byval argv as zstring ptr ptr _
) as long
function = 0 '' quiet the warning
#ifdef __FB_WIN32__
fb___main()
#endif
fb_Init( argc, argv, 0 )
'' ---------------------------------
'' START OF USER'S IMPLICIT MAIN
print "hello"
'' END OF USER'S IMPLICIT MAIN
'' ---------------------------------
fb_End( 0 )
end function
'' but we still need a main to satisfy the linker and start-up code
'' NB: for actual use of '-entry' option this might be defined in
'' another libray or framework
function main cdecl alias "main" _
( _
byval argc as long, _
byval argv as zstring ptr ptr _
) as long
'' just call our custom main
return custom_main( argc, argv )
end function
Code: Select all
'' main4.bas
'' - demostrate alternate named main function
'' as an alternate entry point for the implicit user main
'' - we must compile and link in separate steps, or give a non-existant
'' module name so that fbc doesn't generate the implicit user main
'' compile: $ fbc -c -m main4 main4.bas -entry custom_main
'' compile: $ fbc main4.o
'' OR
'' compile: $ fbc main4.bas -entry custom_main
'' internally the implicit main function is now named "custom_main"
declare function custom_main cdecl alias "custom_main" _
( _
byval argc as long, _
byval argv as zstring ptr ptr _
) as long
'' But we still need a main() function to satisfy the linker and start-up code
'' - this might be defined in another libray or framework
'' - it's not so let's define it here for the demonstration
function main cdecl alias "main" _
( _
byval argc as long, _
byval argv as zstring ptr ptr _
) as long
'' !!!TODO!!! stack alignment???
'' just call our custom main for demonstration
return custom_main( argc, argv )
end function
'' ---------------------------------
'' START OF USER'S IMPLICIT MAIN
'' internally this is named "custom_main" and will automatically be
'' called by our custom frame work
print "hello"
'' END OF USER'S IMPLICIT MAIN
'' ---------------------------------
fxm wrote:changelog.txt:Version 1.09.0
[added]
- fbc: add '-entry name' command line option to set program entry point (TeeEmCee)
Indeed, already this other short description is less leading to confusion.coderJeff wrote:Another description could be: '-entry name' specifies the public exported name of the implicit user main function.
Nice! You the man.