Compile/Run

Working on new editor enhancements?
akee
Enthusiast
Enthusiast
Posts: 498
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Compile/Run

Post 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.
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Compile/Run

Post 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"
akee
Enthusiast
Enthusiast
Posts: 498
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Compile/Run

Post by akee »

Nope... The exe file PureBasic_Compilation0.exe just appeared to the source folder but is not saved as MyPB.exe. :(
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: Compile/Run

Post 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.
사십 둘 .
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: Compile/Run

Post 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.
akee
Enthusiast
Enthusiast
Posts: 498
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Compile/Run

Post 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
Amundo
Enthusiast
Enthusiast
Posts: 200
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: Compile/Run

Post 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?
Win10, PB6.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
akee
Enthusiast
Enthusiast
Posts: 498
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Compile/Run

Post by akee »

Thanks Amundo... :)
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: Compile/Run

Post 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()
Amundo
Enthusiast
Enthusiast
Posts: 200
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: Compile/Run

Post 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.
Win10, PB6.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
Post Reply