Page 1 of 1
Compile/Run
Posted: Sun Sep 26, 2010 12:39 pm
by akee
When you click Compile/Run it creates the executable as PureBasic_Compilation0.exe...
Without using Create Executable, if you have a program MyPB.pb, how do you create MyPB.exe in the souce folder where the .pb file is stored? I tried compiling with /exe "MyPB.exe" option but it does not work.
Re: Compile/Run
Posted: Sun Sep 26, 2010 12:47 pm
by TomS
In the IDE open the Compiler-MenĂ¼ then select Compiler-Options.
Select the Compile/Start-Tab and activate "Create temp Executable in source directory"
Re: Compile/Run
Posted: Mon Sep 27, 2010 2:50 pm
by akee
Nope... The exe file PureBasic_Compilation0.exe just appeared to the source folder but is not saved as MyPB.exe.

Re: Compile/Run
Posted: Mon Sep 27, 2010 4:19 pm
by bobobo
To compile to an execute DO NOT PRESS F5 !!
You compile source to a exe with selecting 'Compiler' in Menu
and then 'Create Executable' in Dropdown.
In IDE-Options you can define a KeyboardShortcut for 'Create Executable'
Alt+F5 f.i.
Re: Compile/Run
Posted: Mon Sep 27, 2010 4:31 pm
by eesau
bobobo wrote:To compile to an execute DO NOT PRESS F5 !!
You compile source to a exe with selecting 'Compiler' in Menu
and then 'Create Executable' in Dropdown.
In IDE-Options you can define a KeyboardShortcut for 'Create Executable'
Alt+F5 f.i.
But he clearly specified "without using Create Executable"...
Anyway, I'm not sure it's possible.
Re: Compile/Run
Posted: Tue Sep 28, 2010 7:35 am
by akee
Guess we have to put this in our Wish list. Maybe we have a chance to get this feature for Christmas...
Anyway, I decided to write my own batch file and link it to the tool with the shortcut Alt-F5.
1. Just create a .bat/.cmd file like MakeRun.cmd
2. Paste the code below in the file.
3. Change the 3 parameters in {braces}
4. Link it to your Tool and set a shortcut for it.
- DONE -
Code: Select all
@echo off
set PB_Folder=C:\Program Files\PureBasic\Compilers\
set PB_Compiler=pbcompiler.exe
set SRC_Folder={replace with the source code folder example C:\MyProject\}
set SRC_Code={your .PB filename}
set SRC_Exe={your .EXE filename}
"%PB_Folder%%PB_Compiler%" "%SRC_Folder%%SRC_Code%" /exe "%SRC_Folder%%SRC_Exe%"
if not exist "%SRC_Folder%%SRC_Exe%" goto NOEXE
echo Running "%SRC_Folder%%SRC_Exe%".
"%SRC_Folder%%SRC_Exe%"
goto END
:NOEXE
echo "%SRC_Folder%%SRC_Exe%" does not exist.
:END
Re: Compile/Run
Posted: Mon Oct 04, 2010 2:52 am
by Amundo
Hi akee,
Thanks for your idea.
I have written this (it uses "GetPartOfFile" from Droopy's lib):
(Windows only, of course!!)
Code: Select all
EnableExplicit
OpenConsole()
#GFP_File = 4
#PB_Folder="C:\Program Files\PureBasic\Compilers\"
#PB_Compiler="pbcompiler.exe"
If CountProgramParameters() < 2
MessageRequester("CompileEXE", "Not enough parameters passed")
CloseConsole()
End
EndIf
Define SRC_Folder$ = ProgramParameter(0)
Debug "SRC_Folder$ = " + SRC_Folder$
PrintN("SRC_Folder$ = " + SRC_Folder$)
Define SRC_Code$ = ProgramParameter(1)
Debug "SRC_Code$ = " + SRC_Code$
PrintN("SRC_Code$ = " + SRC_Code$)
Define SRC_Exe$ = GetPartOfFile(SRC_Code$, #GFP_File) + ".exe"
Debug "SRC_Exe$ = " + SRC_Exe$
RunProgram(#PB_Folder + #PB_Compiler, _
SRC_Code$ + " /exe " + SRC_Folder$ + SRC_Exe$, _
SRC_Folder$, _
#PB_Program_Wait)
If ReadFile(0, SRC_Folder$ + SRC_Exe$)
MessageRequester("CompileEXE", "Compiled " + SRC_Folder$ + SRC_Exe$)
CloseFile(0)
Else
MessageRequester("CompileEXE", "Error compiling " + SRC_Folder$ + SRC_Exe$)
EndIf
CloseConsole()
with the parameters set (for the "Configure Tools") as:
Commandline: "C:\Program Files\PureBasic\CompileEXE.exe" (this is what I compiled the source above to)
Arguments: "%PATH %FILE" (no quotes!!!!!)
and whatever name and shortcut key you want.
Not sure how to detect whether it's an EXE or DLL or CONSOLE program being compiled - does "pbcompiler.exe" read the IDE settings???
If it reports an error compiling, check the console window opened (with OpenConsole() )
Not 100% tested - use with care!!!!
Hope it's useful.
EDIT: Doh! Of course, specifying "/exe" on the commandline will compile to an EXE, not sure how to read what type of compilation is required - can anyone help, please?
Re: Compile/Run
Posted: Mon Oct 04, 2010 6:05 am
by akee
Thanks Amundo...

Re: Compile/Run
Posted: Sun Oct 17, 2010 3:52 pm
by yrreti
Hi Amundo,
As I didn't have the GetPartOfFile Procedure, and some others may not have it, I did it the following way.
Code: Select all
;Purpose: When using Compile/run or F5, to create the programs name.exe instead of
;PureBasic_Compilation#.exe in the source directory.
EnableExplicit
OpenConsole()
#PB_Folder="D:\PureBasic4.5\Compilers\" ;You need to put your correct PureBasic programs location here.
#PB_Compiler="pbcompiler.exe"
If CountProgramParameters() < 2
MessageRequester("CompileEXE", "Not enough parameters passed")
CloseConsole()
End
EndIf
Define SRC_Folder$ = ProgramParameter(0)
PrintN("SRC_Folder$ = " + SRC_Folder$)
Define SRC_Code$ = ProgramParameter(1)
PrintN("SRC_Code$ = " + SRC_Code$)
Define SRC_FileName$ = GetFilePart(SRC_Code$)
PrintN("SRC_FileName$ = " + SRC_FileName$)
Define SRC_Exe$ = Left(SRC_FileName$, Len(SRC_FileName$)-Len(GetExtensionPart(SRC_FileName$))-1) + ".exe"
PrintN("SRC_Exe$ = " + SRC_Exe$)
RunProgram(#PB_Folder + #PB_Compiler, SRC_Code$ + " /exe " + SRC_Folder$ + SRC_Exe$, SRC_Folder$, #PB_Program_Wait)
If ReadFile(0, SRC_Folder$ + SRC_Exe$)
MessageRequester("CompileEXE", "Compiled " + SRC_Folder$ + SRC_Exe$)
CloseFile(0)
Else
MessageRequester("CompileEXE", "Error compiling " + SRC_Folder$ + SRC_Exe$)
EndIf
CloseConsole()
Re: Compile/Run
Posted: Sun Oct 17, 2010 11:16 pm
by Amundo
Good work, yrreti.
I still need to make this more robust and versatile (e.g. getting the install path for PB, instead of having it hard-coded) and finding a way to tell what kind of compile it is (DLL, EXE, etc).
Thanks for sharing.