Page 1 of 1

Command line compiler with #PB_Editor_CreateExecutable...

Posted: Sat Sep 27, 2025 4:00 pm
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?

Re: Command line compiler with #PB_Editor_CreateExecutable...

Posted: Sat Sep 27, 2025 4:09 pm
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

Re: Command line compiler with #PB_Editor_CreateExecutable...

Posted: Sat Sep 27, 2025 4:14 pm
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