Understanding PureBasic compilation
Understanding PureBasic compilation
Would I be correct in saying that PureBasic operates on the principle of converting the source to C and then calling a C compiler? I notice that the compilers sub-folder contains GCC and there is also an SDK sub-folder which refers in the readme file to Visual C.
Last edited by Oso on Thu Dec 28, 2023 8:47 am, edited 1 time in total.
Re: Understanding PureBasic compilation
Transpiling to C is a new v6 option to capture more uprocessors than the original custom coded ASM compiler supported.
The included C compiler may or may not change. Still early.
The options applied during compilation is also in flux. Aggressive optimizations can break code.
Overall, it is an awesome development with smaller, faster exe's!
The included C compiler may or may not change. Still early.
The options applied during compilation is also in flux. Aggressive optimizations can break code.
Overall, it is an awesome development with smaller, faster exe's!
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Understanding PureBasic compilation
Okay, thanks for the explanation, it's interesting. Switching from generating assembler output to C is a significant step. I can say that I like the small footprint and how easy it is to get up and running.skywalk wrote: Wed Jul 20, 2022 1:52 pm Transpiling to C is a new v6 option to capture more uprocessors than the original custom coded ASM compiler supported.
The included C compiler may or may not change. Still early.
The options applied during compilation is also in flux. Aggressive optimizations can break code.
Overall, it is an awesome development with smaller, faster exe's!
I looked at pbcompile.exe and put the compilers sub-folder into my path. Two interesting things...
1. The .pb source file saved with the development environment seems to contain some additional metadata that wasn't entered with the source.
Code: Select all
C:\test>type console2*
´╗┐OpenConsole()
PrintN("Hello, welcome to PureBasic")
Print("What is your name ?")
name.s=Input()
PrintN("")
PrintN("It's good to meet you, "+name)
PrintN("")
Print("Please press Enter to end : ")
Input()
End
; IDE Options = PureBasic 6.00 LTS (Windows - x64)
; CursorPosition = 8
; EnableXP
; DPIAware
2. I have compiler errors when I run
Code: Select all
pbcompile console2.pb
Code: Select all
C:\test>pbcompiler console2.pb
PureBasic 6.00 LTS (Windows - x64) Free
Compiling console2.pb
Loading external libraries...
Starting compilation...
10 lines processed.
Error: Assembler
purebasic.asm [53]:
extrn SetCurrentDirectoryA
processed: extrn SetCurrentDirectoryA
error: symbol already defined.
Incidentally, the code runs fine when I run it (or compile it) via the IDE interface...
Code: Select all
Hello, welcome to PureBasic
What is your name ?Oso
It's good to meet you, Oso
Please press Enter to end :
Re: Understanding PureBasic compilation
C:\test>type console2*
´╗┐OpenConsole()
First 3 bytes: This is the BOM (here display as text)
Because source are save as Utf-8 with BOM
and at end, in comment, this is the preferences of the file

´╗┐OpenConsole()
First 3 bytes: This is the BOM (here display as text)
Because source are save as Utf-8 with BOM
and at end, in comment, this is the preferences of the file

Last edited by Marc56us on Wed Jul 20, 2022 3:29 pm, edited 3 times in total.
Re: Understanding PureBasic compilation
For me, the exe's created with the 'C' backend run slower than same exe created with the 'ASM' backend. Might only be milliseconds is some cases but still slower.skywalk wrote: Wed Jul 20, 2022 1:52 pm Overall, it is an awesome development with smaller, faster exe's!
Yes the exe size may be a few KB's smaller but certainly not worth the wait. I have one app when compiled with 'C' backend is 192KB smaller than the 'ASM' version but it takes 18 seconds to compile compared to 2 seconds with the 'ASM' backend. I can only imagine how painful the wait on a slow computer.
Re: Understanding PureBasic compilation
I have also made a comparison between ASM and C-Backend.
It is indeed the case that the ASM backend is minimally faster than the C backend.
BUT, if the compiler option 'Optimize generate code' is enabled, the C backend program is a good 20% faster.
It is indeed the case that the ASM backend is minimally faster than the C backend.
BUT, if the compiler option 'Optimize generate code' is enabled, the C backend program is a good 20% faster.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Understanding PureBasic compilation
If that is what you are seeing then you are very lucky.mk-soft wrote: Wed Jul 20, 2022 4:00 pm BUT, if the compiler option 'Optimize generate code' is enabled, the C backend program is a good 20% faster.
Unfortunately I'm just not seeing that here when compiling every day Windows apps used in a daily work environment.
At least the ASM choice wasn't removed so all is good

- VB6_to_PBx
- Enthusiast
- Posts: 627
- Joined: Mon May 09, 2011 9:36 am
Re: Understanding PureBasic compilation
which one would be more difficult to be Decompiled or Hacked ?I have also made a comparison between ASM and C-Backend.
or would there be no difference ?
PureBasic .... making tiny electrons do what you want !
"With every mistake we must surely be learning" - George Harrison
Re: Understanding PureBasic compilation
How is that done though, incidentally? Is it through Compiler Options? I've just been looking for it and I see there's an option to choose the compiler, but mine only offers PureBasic 6.00 Windows x64. Perhaps that's because I've only just downloaded a trial, maybe?
To be honest I think the flexibility with this product places it substantially ahead of many others, even if there is a performance cost as you've indicated. I feel I've been screwed in the past because Microsoft moves the goalposts and trashes the investment we have in our software.
What does the future hold for PureBasic? I take it that PureBasic isn't open source, so what if the developer decides to do something else in the future? I only ask this in the nicest possible way - not to find fault with it, but just to ask the obvious question.
Re: Understanding PureBasic compilation
Thanks for the explanation on the BOM. The question was what do I do to make the following work? Am I meant to strip out that BOM and the metadata, or simply create the source file using a notepad editor that doesn't insert that? What's the correct approach, given that pbcompiler rejects the source file that otherwise compiles okay through the GUI tools?
Code: Select all
pbcompiler console2.pb
Re: Understanding PureBasic compilation
Whatever. PB does not care of BOM in source code and if source is ASCII or Utf-8. This is juste for you (ie: take care of locale chars). You can even use Vi or Edline to make source
Compilers: Even for free version, there is 2 (command line) compilers. C backend have 'c' as suffix of exe
The ASM version (change dir with your)
The version without Backend C in name is the ASM version
C:\Program Files\PureBasicFree\Compilers>pbcompiler.exe /version
PureBasic 6.00 LTS (Windows - x64) Free - (c) 2022 Fantaisie Software
The C version
C:\Program Files\PureBasicFree\Compilers>pbcompilerc.exe /version
PureBasic 6.00 LTS - C Backend (Windows - x64) - (c) 2022 Fantaisie Software
If you don't see C version in IDE, add-it
File > Preferences > Compiler > [...] (search pbcompilerc.exe) > Add > Ok
Very few people are able to ensure the continuity of the work of a single person. We see this for a small part of PB: the IDE is opensource and few people are able to modify it.
So for your programs, having the source of the compiler is not a guarantee of choice of solutions. In real life, when it comes to programs, the work of the analyst (pseudo-code) is often more important than that of the coder to ensure the durability of an application.
And for last question: to compile with command line tool, you need to set PUREBASIC_HOME to the root of you PB dir
PUREBASIC_HOME=C:\Program Files\PureBasic
Enjoy


Compilers: Even for free version, there is 2 (command line) compilers. C backend have 'c' as suffix of exe
The ASM version (change dir with your)
The version without Backend C in name is the ASM version
C:\Program Files\PureBasicFree\Compilers>pbcompiler.exe /version
PureBasic 6.00 LTS (Windows - x64) Free - (c) 2022 Fantaisie Software
The C version
C:\Program Files\PureBasicFree\Compilers>pbcompilerc.exe /version
PureBasic 6.00 LTS - C Backend (Windows - x64) - (c) 2022 Fantaisie Software
If you don't see C version in IDE, add-it
File > Preferences > Compiler > [...] (search pbcompilerc.exe) > Add > Ok
Very few people are able to ensure the continuity of the work of a single person. We see this for a small part of PB: the IDE is opensource and few people are able to modify it.
So for your programs, having the source of the compiler is not a guarantee of choice of solutions. In real life, when it comes to programs, the work of the analyst (pseudo-code) is often more important than that of the coder to ensure the durability of an application.
And for last question: to compile with command line tool, you need to set PUREBASIC_HOME to the root of you PB dir
PUREBASIC_HOME=C:\Program Files\PureBasic
Enjoy

Last edited by Marc56us on Wed Jul 20, 2022 9:03 pm, edited 1 time in total.
Re: Understanding PureBasic compilation
Yes, I was referring to C backend + optimized.Paul wrote: Wed Jul 20, 2022 4:56 pmIf that is what you are seeing then you are very lucky.mk-soft wrote: Wed Jul 20, 2022 4:00 pm BUT, if the compiler option 'Optimize generate code' is enabled, the C backend program is a good 20% faster.
Unfortunately I'm just not seeing that here when compiling every day Windows apps used in a daily work environment.
At least the ASM choice wasn't removed so all is good![]()
I believe the C backend can only get better.
The ASM may not get the attention you seek. It already does not support ARM uprocessors.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Understanding PureBasic compilation
Thanks for the reply. Setting PUREBASIC_HOME to C:\Program Files\PureBasic made no difference to the result. Clearly there's something fundamental and very simple that I'm misunderstanding here.Marc56us wrote: Wed Jul 20, 2022 8:48 pmAnd for last question: to compile with command line tool, you need to set PUREBASIC_HOME to the root of you PB dir
PUREBASIC_HOME=C:\Program Files\PureBasic
I have my source code in C:\Test
I've added C:\Program Fles\PureBasic\Compilers to PATH
I open a shell and change directory to C:\Test
The result of pbcompilerc :
Code: Select all
C:\test>pbcompilerc console2.pb
PureBasic 6.00 LTS - C Backend (Windows - x64) Free
Loading 'C' subsystem
Compiling console2.pb
Loading external libraries...
Starting compilation...
10 lines processed.
Creating and launching executable.
Error: Linker
error: Unresolved external symbol '_SetCurrentDirectoryA' - referenced from 'PureBasic.obj'.
POLINK: fatal error: 1 unresolved external(s).
Code: Select all
C:\test>pbcompiler console2.pb
PureBasic 6.00 LTS (Windows - x64) Free
Compiling console2.pb
Loading external libraries...
Starting compilation...
10 lines processed.
Error: Assembler
purebasic.asm [53]:
extrn SetCurrentDirectoryA
processed: extrn SetCurrentDirectoryA
error: symbol already defined.
It indicates that /COMMENTED "creates a commented '.asm' output file when creating an executable". It doesn't mention anything about C source, although that works too for pbcompilerc.
There's also a /EXE given in an example command, but /EXE is not explained in the list of allowed options, so there's indication what it's for,...
... Anyway, it's very odd that the compilers do not compile valid source code until I add the /COMMENTED switch, although those routines compile perfectly through the GUI interface. It seems therefore that something is not quite right.Examples:
CLI> pbcompiler "C:\Project\Source\DLLSource.pb" /EXE "C:\Project\project.dll" /DLL
Re: Understanding PureBasic compilation
[Edit 10:15]
Tested on a PC with only one PB installation (PB 6.00 FREE Win 11 x64), the compilation works well in ASM and C (without PATH neither PB_HOME)
But in both cases, you have to put /OUTPUT followed by a name

Tested on a PC with only one PB installation (PB 6.00 FREE Win 11 x64), the compilation works well in ASM and C (without PATH neither PB_HOME)
But in both cases, you have to put /OUTPUT followed by a name
Code: Select all
C:\Test>"\Program Files\PureBasic\Compilers\pbcompiler.exe" console2.pb /output console2.exe
PureBasic 6.00 LTS (Windows - x64) Free
Compiling console2.pb
Loading external libraries...
Starting compilation...
10 lines processed.
Creating executable "console2.exe".
- Feel the ..PuRe.. Power -
C:\Test>"\Program Files\PureBasic\Compilers\pbcompilerc.exe" console2.pb /output console3.exe
PureBasic 6.00 LTS - C Backend (Windows - x64) Free
Loading 'C' subsystem
Compiling console2.pb
Loading external libraries...
Starting compilation...
10 lines processed.
Creating executable "console3.exe".
- Feel the ..PuRe.. Power -

Last edited by Marc56us on Thu Jul 21, 2022 9:15 am, edited 1 time in total.
Re: Understanding PureBasic compilation
Parameters wrong ...
Examples:
Link: IDE-Tool Display ASM Code
Examples:
Compiler File Path: D:\WinAPP\PureBasic600x64\Compilers\pbcompiler.exe
Compiler Parameters: --commented -co PB_Editor_BuildCount=0 -co PB_Editor_CompileCount=0 --unicode --output "C:\Users\XXX\AppData\Local\Temp\purebasic"
ASM Code File Path:D:\WinAPP\PureBasic600x64\Compilers\purebasic.asm
Link: IDE-Tool Display C CodeCompiler File Path: D:\WinAPP\PureBasic600x64\Compilers\pbcompilerc.exe
Compiler Parameters: --commented -co PB_Editor_BuildCount=0 -co PB_Editor_CompileCount=0 --unicode --output "C:\Users\XXX\AppData\Local\Temp\purebasic"
C-Code File Path:D:\WinAPP\PureBasic600x64\Compilers\purebasic.c
Link: IDE-Tool Display ASM Code
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive