Command line compiler with #PB_Editor_CreateExecutable...

Just starting out? Need help? Post your questions and find answers here.
Axolotl
Addict
Addict
Posts: 865
Joined: Wed Dec 31, 2008 3:36 pm

Command line compiler with #PB_Editor_CreateExecutable...

Post by Axolotl »

Using the command line compiler with source code that contains the following line results in an error.

Code: Select all

#ProgramVersion$       = "0." + #PB_Editor_BuildCount + "." + #PB_Editor_CompileCount 
I've thrown together the following for this message.

Code: Select all

EnableExplicit

; Error with external compiler use..... 

;#ProgramVersion$       = "0." + #PB_Editor_BuildCount + "." + #PB_Editor_CompileCount 
;
#ProgramVersion$       = "0.0" ;+ #PB_Editor_BuildCount + "." + #PB_Editor_CompileCount 

#ProgramCaption$       = "Compiler Test " 

; Debug #PB_Editor_CreateExecutable   ; <= not working with Debugger On 

; ---

Global PureBasicHome$, WorkDir$, InputFile$, OutputFile$ 

CompilerIf #PB_Compiler_Debugger
	PureBasicHome$ = #PB_Compiler_Home
	InputFile$     = #PB_Compiler_File 

CompilerElse
	PureBasicHome$ = GetEnvironmentVariable("PUREBASIC_HOME")
	InputFile$     = ProgramParameter() 

CompilerEndIf

; ---

Procedure Add(Message$) 
  AddGadgetItem (0, -1, Message$) 
; SetGadgetState(0, CountGadgetItems(0)-1) 
EndProcedure 

; ---

Procedure RunCompiler(Command$) 
  Protected ec, Compiler 
  
  If Not Asc(Command$) : Command$ = "-h" : EndIf 
  Compiler = RunProgram(#PB_Compiler_Home+"compilers/pbcompiler", Command$, WorkDir$, #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide) 
  Add("Run with Command: " + Command$ + "") 
  If Compiler
    While ProgramRunning(Compiler)
      If AvailableProgramOutput(Compiler)
        Add(ReadProgramString(Compiler)) 
      EndIf
    Wend
    ec = ProgramExitCode(Compiler) 
    Add("") 
    Add("Exitcode: " + Str(ec)) 
    CloseProgram(Compiler) 
  EndIf
EndProcedure 

; ---

Procedure Main() 
  Protected res$, opt$  
  
  If OpenWindow(0, 0, 0, 808, 248, #ProgramCaption$, #PB_Window_SystemMenu | #PB_Window_ScreenCentered) 
    ListViewGadget(0, 4, 4, 800, 240) 

    ; init ..... 
    ;
    WorkDir$ = GetPathPart(InputFile$) 
    OutputFile$ = WorkDir$ + "PureBasic_MyApp.exe"  ; this is waht I want 

    If FileSize(InputFile$) < 0 : res$ = "not " : EndIf 
    Add("InputFile " + #DQUOTE$ + InputFile$ + #DQUOTE$ + " is " + res$ + "existing.") 

    If FileSize(OutputFile$) < 0 : res$ = "not " : EndIf 
    Add("OutputFile " + #DQUOTE$ + OutputFile$ + #DQUOTE$ + " is " + res$ + "existing.") 

    If FileSize(OutputFile$) > -1 And Not DeleteFile(OutputFile$, #PB_FileSystem_Force) 
    	Add(" Cannot delete OutputFile " + #DQUOTE$ + OutputFile$ + #DQUOTE$) 
    EndIf

    Add("Run Compiler .....") 

    opt$ = "-d "  ; debugger on 

    RunCompiler(opt$ + #DQUOTE$ + InputFile$ + #DQUOTE$ + " -o " + #DQUOTE$ + OutputFile$ + #DQUOTE$) 

    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
    CloseWindow(0) ; we are done...
  EndIf

  ; Clean up, because this is only a compile test. Don't leave any trash behind. 
  ;
  If FileSize(OutputFile$) > 0 
    If MessageRequester(#ProgramCaption$ + "Info", "OutputFile found:" + #LF$ + OutputFile$ + #LF$ + "Delete it now?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes 
      DeleteFile(OutputFile$, #PB_FileSystem_Force) 
    EndIf   
  Else 
  	MessageRequester(#ProgramCaption$ + "Error", "OutputFile not found:" + #LF$ + OutputFile$ + #LF$ + "Probably the source contains errors.") 
  EndIf 
  ProcedureReturn 0 
EndProcedure 

End Main() 
Where is the mistake?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User_Russian
Addict
Addict
Posts: 1572
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Command line compiler with #PB_Editor_CreateExecutable...

Post by User_Russian »

These constants are added by the IDE using the parameter /CONSTANT on the compiler command line.
https://www.purebasic.com/documentation ... piler.html
Axolotl
Addict
Addict
Posts: 865
Joined: Wed Dec 31, 2008 3:36 pm

Re: Command line compiler with #PB_Editor_CreateExecutable...

Post by Axolotl »

The question is how can I use them with the IDE values.
The help shows me this, but I don't have the IDE-internal counter values.

Code: Select all

/CONSTANT MyConstant=10 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply