Page 1 of 1

Version information when compiling on the command line

Posted: Thu Feb 26, 2026 9:41 pm
by Little John
Hi all,

can the command line compiler access the version information contained in the source file, or is the version information only available in the IDE?

Background of the question:
Normally I edit my PB source codes using the IDE, and then compile the programs from the IDE.
Recently I compiled one of those working codes that contained version information on the command line, and got an error.

For example, the following code runs fine from the IDE. But when compiling on the command line with pbcompiler.exe or pbcompilerc.exe (PB 6.30 on Windows), I get “Error: Line 3 - Constant not found: #PB_Editor_FileDescription.”.

Code: Select all

#ProgName$ = "Foo"
#Version$ = "1.00"
#Description$ = #PB_Editor_FileDescription  ; #PB_Editor_FileDescription contains the content of VersionField6.
#Copyright$ = "© Me 2026"

MessageRequester("Test", #Description$)

; IDE Options = PureBasic 6.30 (Windows - x64)
; EnableXP
; EnableUser
; DPIAware
; DllProtection
; EnableExeConstant
; IncludeVersionInfo
; VersionField6 = MyDescription

Re: Version information when compiling on the command line

Posted: Fri Feb 27, 2026 1:43 pm
by Axolotl
Yes, your assumption is absolutely correct.
All IDE options must be passed to the compiler yourself.

I copied the imho relevant / important to know parts from the help file.
Send the information to the compiler with this switch:
-co, --constant, /CONSTANT name=value: creates the specified constant with the given expression. Example: 'pbcompiler test.pb /CONSTANT MyConstant=10'. The constant #MyConstant will be created on the fly with a value of 10 before the program gets compiled.
In addition to the IDE options, there is also this information
When the %TEMPFILE or %COMPILEFILE tokens are used, the IDE appends the compiler options as a comment to the end of the created temporary file, even if the user did choose to not save the options there when saving a source code.
This enables your tool to read the compiler settings for this file, and take them into account for the actions your carries out.

Re: Version information when compiling on the command line

Posted: Fri Feb 27, 2026 1:47 pm
by benubi
This means these are set by the IDE, the PureBasic IDE will set the #PB_Editor_XYZ and other constants at compile time (the "editor" is the IDE).

You can also set manually a list of constants using a parameter in the command line, for multiple constants simply rinse & repeat for each:
PureBasic Help wrote: -co, --constant, /CONSTANT name=value: creates the specified constant with the given expression. Example: 'pbcompiler test.pb /CONSTANT MyConstant=10'. The constant #MyConstant will be created on the fly with a value of 10 before the program gets compiled.


You could also set default values for the IDE constants that you are using, if you want your code to be more comfy to compile:

Code: Select all

CompilerIf Not Defined(PB_Editor_FileDescription, #PB_Constant)

#PB_Editor_FileDescription = "Default description"
; (...)
; other constants imported from the PureBasic IDE
; 
CompilerEndIf

You can play with this kind of "switches" in the IDE settings in a way you could for example use a compile constant that tells if the program should compile with all features or only a demo-version of your app, to include or exclude features and such things. You could create a simple constant in the IDE, demo=1 or the opposite full_version=1, depending on what you favor for your "default compiling behavior". If it's not defined at compile time the source code could branch to be compiled as if the constant was equal to zero.

Code: Select all

; set #compile_as_demo=1 in the project target's or standalone source file's compiler options
CompilerIf Not Defined(compile_as_demo, #PB_Constant)
; here is default behavior
; before we want to turn off features in a demo, we want to focus on creating them first ;o)
; by default the full version should compile
;
; things only available in full version:
XInclude "full_version_fix.pb" 
;
CompilerElseIf Not #compile_as_demo  ; (same as =0)
; here the constant was set in the IDE either in the project target's settings or in the standalone source file (main source file)
; or it was manually set with /constant parameter
; or you defined it earlier in the code, but forgot about it ;)
;
; things only available in full version
XInclude "full_version_fix.pb"
;
CompilerElse
; constant was manually set to be non-zero in the IDE or manually with parameter, this means we want to build the demo version
;
XInclude "demo_version_fix.pb"
;
CompilerEndif 

; demo & full versions shared code continues here
Hope I could give you some help and inspiration for experiments.

Re: Version information when compiling on the command line

Posted: Fri Feb 27, 2026 11:06 pm
by Andre
Thanks four suggestions, benubi :D

As this topic is also related to this one: viewtopic.php?t=88369

Re: Version information when compiling on the command line

Posted: Sat Feb 28, 2026 6:55 pm
by Little John
Axolotl and benubi, thanks for your replies and suggestions!

Especially reminding me of

Code: Select all

Defined(..., #PB_Constant)
helps me to work around the problem. It seems I had forgotten about that compiler function. :shock:

Re: Version information when compiling on the command line

Posted: Sun Mar 01, 2026 1:23 am
by ChrisR
A workaround to play with

Code: Select all

; CmdLine compile: D:\PureBasic\Portable\PureBasic_Windows_X64_6.30\Compilers\pbcompiler.exe D:\PureBasic\Test\_Test.pb /EXE D:\PureBasic\Test\_Test.exe /XP /DPIAWARE

#ThisSourceFile$ = "D:\PureBasic\Test\_Test.pb"
#IDEOptions$ = "; IDE Options = PureBasic"

CompilerIf Defined(PB_Editor_FileDescription, #PB_Constant) ; Change to an unknown constant for debugging
  Description$ = #PB_Editor_FileDescription
  Description$ = "FileDescription (IDE compile) = " + Description$
CompilerElse
  If PeekA(?SourceFile) = $EF And PeekA(?SourceFile+1) = $BB And PeekA(?SourceFile+2) = $BF ; Detect BOM UTF-8
    Source$ = PeekS(?SourceFile, -1, #PB_UTF8)
  Else
    Source$ = PeekS(?SourceFile, -1, #PB_Ascii)
  EndIf
  
  Pos = FindString(Source$, #IDEOptions$, 2)
  If Pos
    Pos = FindString(Source$, #IDEOptions$, Pos+25)
    If Pos
      Source$=Mid(Source$, Pos)
      
      Pos = FindString(Source$, "VersionField6", 2)
      If Pos
        Pos2 = FindString(Source$, #CRLF$, Pos+16)
        If Pos2
          Description$ = Mid(Source$, Pos+16, Pos2-Pos-16)
        Else
          Description$ = Mid(Source$, Pos+16)
        EndIf
        Description$ = "FileDescription (CmdLine compile) = " + Description$
      EndIf
    EndIf
  EndIf
  
  DataSection
    SourceFile:
    IncludeBinary #ThisSourceFile$
    Data.b 0
  EndDataSection
CompilerEndIf

MessageRequester("Test PB FileDescription", Description$)

; IDE Options = PureBasic 6.30 (Windows - x64)
; EnableXP
; DPIAware
; Executable = _test.exe
; IncludeVersionInfo
; VersionField6 = MyDescription

Re: Version information when compiling on the command line

Posted: Mon Mar 02, 2026 1:57 pm
by Little John
Hello ChrisR, thanks for your code!

Yes, I will choose this method to read the version information. However, it is a pity that the command line compiler cannot process the version information itself.

Re: Version information when compiling on the command line

Posted: Mon Mar 02, 2026 8:17 pm
by ChrisR
Hello Little John,
Yes, I agree, the command line compiler should do it, it has everything at hand to do it (without the need to include the source), it would be a bonus.
This topic should be moved to feature request, I guess.

ps: It's really not easy, it"s difficult to navigate and respond right now when it takes 20 seconds for each click. It gives the forum a bad image :x Fred need to find a solution for these , these greedy-ass AI chatbots :twisted: