[Gambas-user] know if program is compiled

Charlie Reinl Karl.Reinl at ...2345...
Sun Jun 14 12:44:35 CEST 2015


Am Sonntag, den 14.06.2015, 11:58 +0200 schrieb Tobias Boege:
> On Sun, 14 Jun 2015, adamnt42 at ...626... wrote:
> > On Sun, 14 Jun 2015 10:19:08 +0200 Marco Ancillotti <gambas at ...3466...> wrote:
> > > Hi all,
> > > 
> > > is there a way to detect from a gambas program if it's running under the 
> > > ide or is compiled into a .gambas file ?
> > > 
> > > thank's in advance.
> > > 
> > 
> > #If Exec
> > ' ...  do whatever
> > #End
> > 
> > hth
> > bruce
> > 
> 
> This seems to work but I had to dig into the compiler's source code to
> verify it. Then I saw that "gbc3 --help" mentions the "-x" switch which
> defines the Exec preprocessor constant [ I will update the documentation
> in a second if no one objects ]. But apparently it doesn't do anything
> else, like *forcing* the creation of an archive, which is where this method
> begins to fail. I can write the following project:
> 
>   Public Sub Main()
>   #If Exec
>     Debug "Exec"
>   #Else
>     Debug "No Exec"
>   #Endif
>   End
> 
> The IDE is nice in that it uses "gbc3 -x" if and only if it creates an
> executable archive (see Project.module:GetCompileCommand) -- then the
> Exec flag trick works. But I can go into a terminal and do
> 
>   $ cd /tmp/exec-flag  # which is my test project above
>   $ gbc3 -ga  # without -x
>   $ gba3
>   $ ./exec-flag.gambas
>   MMain.Main.7: No Exec
> 
> but I clearly started an executable archive. On the other side I can do
> 
>   $ gbc3 -gax
>   $ gbx3
>   MMain.Main.5: Exec
> 
> but I didn't run it from an executable archive. So, the Exec flag trick
> works if you expect people to compile stuff via the IDE.
> 
> Also, you should know that there is at least a third way to run a program,
> as I have already shown above:
> 
>   $ gbx3 /tmp/exec-flag  # if it was compiled before
> 
> which runs outside of the IDE but doesn't create a .gambas archive.
> 
> So, you might ask yourself now why it is so difficult to determine whether
> you run from an executable archive or not. The answer is: you shouldn't
> care. Write your program properly :-)
> 
> Regads,
> Tobi
> 

Salut,

I use since gambas1 the IDE arguments (which only available in the IDE).
I set a ISIDE, if in any form pressend it comes from the IDE

SUB chkIfIsIDE()
DIM nI AS Integer
    bIsIDE = FALSE
    FOR nI = 0 TO Application.Args.Count - 1
'        PRINT Application.Args[nI]
        IF Instr(UCase(Application.Args[nI]), "ISIDE") > 0 THEN
            bIsIDE = TRUE
        ENDIF
    NEXT
END
-- 
Amicalement
Charlie





More information about the User mailing list