Repository navigation
Compiler Option Entry
Home › Compiler Option: -entry
Override the public exported name of the implicit user main function
Syntax
-entry < name >
Parameters
name
The custom name that overrides the public exported name of the implicit user main function
Description
The -entry compiler option changes the name of the publicly export symbol of the implicit user main function (automatically generated by the compiler as start-up code).
It affects the start-up code and implicit user main, which is also affected by the module being the main module or not.
By default, the compiler defines a publicly exported 'main' symbol in the main module as required by the run time start-up system code.
There is no other way currently to override the compiler's use of the 'main' symbol other than to always compile and link separately.
Proceedings:
- The custom main function name must only be declared with the following signature (same parameter types, same return type, same calling convention) to be compatible with the (basic) main function:
'' 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- The (basic) main function must also be provided to satisfy the linker and start-up code. This might be defined in another libray or framework, in C, or ASM, or fb language as shown by the following minimum code example:
Function main cdecl Alias "main" ( ByVal argc As Long, ByVal argv As ZString Ptr Ptr ) As Long
'' .....
'' call the custom main
Return custom_main( argc, argv )
End Function- Then compile with the -entry custom_main option.
Note:
This feature is being developed and may change in future (see Compiler Option: -entry in Documentation forum).
There will maybe a better way to deal with this: a compiler option that lets to outright specify an explicit "main".
Example
Example of program (option_entry.bas) trying to show the minimal code for fb language only:
'' option_entry.bas:
'' - demonstrate alternate named main function
'' as an alternate entry point for the implicit user main
'' - we also can compile and link in separate steps
'' compile: $ fbc -c -m option_entry option_entry.bas -entry custom_main
'' compile: $ fbc option_entry.o
'' OR
'' compile: $ fbc option_entry.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
'' 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"
Sleep
'' END OF USER'S IMPLICIT MAIN
'' ---------------------------------Version
See also
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing