Page 1 of 1

Compiler Directives

Posted: Thu Oct 01, 2020 2:48 am
by Gary.Maine
When dealing with cross platform apps, It would be helpfull to have a complile driective like #Compile_Console

Re: Compiler Directives

Posted: Thu Oct 01, 2020 4:58 am
by helpy
Just searched the PureBasic help:
Reserved Constants
The PureBasic compiler has several reserved constants which can be useful to the programmer:

Code: Select all

#PB_Compiler_ExecutableFormat : Determines executable format. It can be one of the following:
    #PB_Compiler_Executable : Regular executable
    #PB_Compiler_Console    : Console executable (have an effect only on Windows, other act like a regular executable)
    #PB_Compiler_DLL        : Shared DLL (dynlib on MacOS X and shared object on Linux)

Re: Compiler Directives

Posted: Thu Oct 01, 2020 6:32 pm
by Gary.Maine
Thanks!

Re: Compiler Directives

Posted: Fri Oct 02, 2020 1:22 am
by Gary.Maine
Nope, #PB_Compiler_Console = Syntax error Under Linux.

I will find a work around ..... but thanks for the responce.

Re: Compiler Directives

Posted: Fri Oct 02, 2020 8:09 am
by Shardik
Gary.Maine wrote:Nope, #PB_Compiler_Console = Syntax error Under Linux.
The following code doesn't display any syntax error on my Lubuntu 18.04 with LXDE regardless if it is compiled with Executable Format "Linux" or "Console":

Code: Select all

CompilerSelect #PB_Compiler_ExecutableFormat
  CompilerCase #PB_Compiler_Executable
    MessageRequester("Info", "Executable format: Executable")
  CompilerCase #PB_Compiler_Console
CompilerSelect #PB_Compiler_ExecutableFormat
  CompilerCase #PB_Compiler_Executable
    MessageRequester("Info", "Executable format: Executable")
  CompilerCase #PB_Compiler_Console
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows
      OpenConsole("Executable format detection")
    CompilerEndIf

    PrintN("ExecutableFormat: Console")
    PrintN("Press <Enter> to continue!")
    Input()
  CompilerCase #PB_Compiler_DLL
    MessageRequester("Info", "Executable format: Library (.dll, .so or .dylib)")
CompilerEndSelect
  CompilerCase #PB_Compiler_DLL
    MessageRequester("Info", "Executable format: Library (.dll, .so or .dylib)")
CompilerEndSelect
But unfortunately the detection of console mode doesn't work in Linux and MacOS: you always obtain "Executable format: Executable" as documented in the help:
[color=#0040FF][u]Help for Compiler Directives[/u][/color] wrote:#PB_Compiler_Console: Console executable (have an effect only on Windows, other act like a regular executable)