blitzCC problem

Blitz3D Forums/Blitz3D Programming/blitzCC problem

bytecode77(Posted 2007) [#1]
hi!

i tried to make a simple compiler using the blitzCC compiler.
when you run compiler.bb, the blitzcc will compile and run test.bb
when you compile the compiler.bb to an exe and run that, it won't compile the test program anymore!?
is there a solution?

thank you.

compiler.bb
blitzcc$ = "D:\Programme\Blitz3D\"

CompileToExe("program.bb", blitzcc$)

Function CompileToExe(path$, blitzcc$)
blitzcc$ = Replace(blitzcc$, "/", "\")
If Right(blitzcc$, 1) <> "\" Then blitzcc$ = blitzcc$ + "\"
ExecFile blitzcc$ + "Bin\blitzcc.exe " + Chr(34) + path$ + Chr(34)
End Function


test.bb
Print "Hello world!"
RuntimeError "Hello world!"
End



Ked(Posted 2007) [#2]
It works for me when I do it like this:

ExecFile ""+chr(34)+"C:/Program Files/Blitz3D/bin/blitzcc.exe"+chr(34)+" "+chr(34)+"C:/test.bb"+chr(34)+""


I think you need the quotes around the location of the compiler also.


bytecode77(Posted 2007) [#3]
it doesnt work either!
it just quits the compiling proccess...
also i tried it with your method AND i copied the test.bb in the c:\ drive of course!


Ked(Posted 2007) [#4]
Do you have the latest Blitz3D?


bytecode77(Posted 2007) [#5]
yes i do.


jfk EO-11110(Posted 2007) [#6]
did you replace the ExecFile line by

print the path
waitkey()

and then visually check what it really does?


bytecode77(Posted 2007) [#7]
yes i did. i also tried a few parameters like -d or -c...
everything is working. but when i compile the compiler.bb, it won't work anymore.


Chalky(Posted 2007) [#8]
Hmmm. This is a total guess - and someone who knows how the IDE interacts with blitcc.exe might know better - but doesn't the IDE pass the CurrentDir() to blitzcc.exe? If you move file test.bb somewhere safe (so that the IDE no longer 'knows' where to find it [i.e. it's not in your default .bb folder or in the last folder accessed via the file requester]) does compiler.bb still work when run from inside the IDE?

In Ked's example he has explicitly specified "c:/test.bb" and so blitzcc.exe knows where to find the source file.

How are you passing compiler.exe the name of the blitz source file - do you include the full pathname?


jfk EO-11110(Posted 2007) [#9]
I meant with the compiled compiler.bb


Chalky(Posted 2007) [#10]
So did I!!!

It has to be something that IS being supplied via the IDE, which ISN'T when running the compiled version. If the IDE is passing the relevant path (for "test.bb") to blitzcc.exe then compiler.bb will work. However, this will not happen when you run the compiled version - hence you will need to supply the source-file's directory, or blitzcc.exe won't know where to find "test.bb".

I'm suggesting that Ked's example worked because he included "c:/" in the filename (I assume you're hard-coding the name of the file to be compiled?) before he compiled compiler.bb. Then when he ran compiler.exe, it passed "c:/test.bb" rather than "test.bb" to blitzcc.exe.

Are you including the full directory name, or just specifying "test.bb"?

Of course I could be barking up completely the wrong tree...


bytecode77(Posted 2007) [#11]
i ceartainly did try to use the path c:\test.bb
also i tried it with your method AND i copied the test.bb in the c:\ drive of course!


hmh. if you run compiler.bb it works perfect, but if you compile the compiler.bb file and run compiler.exe, it just wont run the test.bb file anymore. thats what panics me...


Chalky(Posted 2007) [#12]
Hmmm. When you say "it works perfect" - what do you mean? I'm asking because I just ran your code via the IDE (having first created "test.bb") and it simply ran before saying "Program has ended".

On your system when you run compiler.bb via the IDE is source file "test.bb" compiled into program "test.exe"? Coz on my system it wasn't...


jfk EO-11110(Posted 2007) [#13]
you´re right, it´s spooky...

chalky - no, it´s executing test.bb. To create an exe you´d need to -o parameter.


Chalky(Posted 2007) [#14]
Aah - I see - it was the name of the function that threw me there - hehe!!! Hmmm - well "test.bb" wasn't executed either!

[edit]
Ok - got this to work via IDE and compiled EXE [by surrounding whole command line parm with chr$(34)'s and adding "(" and ")" to ExecFile command]:
blitzcc$ = "C:/Program Files/Blitz3D/"

CompileToExe("test.bb", blitzcc$)
End

Function CompileToExe(path$, blitzcc$)
	blitzcc$ = Replace(blitzcc$, "/", "\")
	If Right(blitzcc$, 1) <> "\" Then blitzcc$ = blitzcc$ + "\"

	blitzcc$=Chr$(34)+blitzcc$+"Bin\blitzcc.exe " + Chr(34) + path$ + Chr(34)+Chr$(34)
	ExecFile(blitzcc$)
End Function

HOWEVER - nothing is displayed even though compilation is now taking place. Or I THINK it is...


bytecode77(Posted 2007) [#15]
On your system when you run compiler.bb via the IDE is source file "test.bb" compiled into program "test.exe"? Coz on my system it wasn't...
no, this compiler.bb code compiles the program directly into RAM

hm. someone like mark or skidracer should be looking at this right now! i know they are... a topic like "blitzCC problem" can't be overseen by them
so... what do you say?


Chalky(Posted 2007) [#16]
Hurrah - I have duplicated [and fixed] your problem at last! Since blitzcc.exe was evidently failing when called outside the IDE, I tried executing blitzcc.exe via a command line window, and got the following error msg:

"Can't find blitzpath environment variable"

I therefore created an environment variable called "blitzpath" with a value of "c:\program files\blitz3d\" (my blitz3d.exe path) and compiler.exe compiled and executed "test.bb" as if it had been done via the IDE!

Now - if I'd only read the instructions in file "versions.txt" - I could have solved that several hours ago... :o/


Ked(Posted 2007) [#17]
I was doing research about this and found this information:


-h : Show Help
-q : Operate quietly
+q : Operate very quietly
-d : Compile and run in debug mode
-k : Print a list of all keywords
+k : Print a list of all keywords and quickhelp
-o exefile$ : Create an executable with the name/location inside the exefile$ string



EXAMPLE: "blitzcc.exe" "test.bb"
EXAMPLE: "C:/Program Files/Blitz3D/bin/blitzcc.exe" -o "testexe.exe" "test.bb"

So in Blitz it shoud look like:
ExecFile(chr$(34)+"C:/Program Files/Blitz3D/bin/blitzcc.exe"+chr$(34)+" "+chr$(34)+"C:/test.bb"+chr$(34))


By the way,
blitzcc$ = "C:\Program Files\Blitz3D\"

CompileToExe("test.bb", blitzcc$)
End

Function CompileToExe(path$, blitzcc$)
	blitzcc$ = Replace(blitzcc$, "/", "\")
	If Right(blitzcc$, 1) <> "\" Then blitzcc$ = blitzcc$ + "\"

	blitzcc$=Chr$(34)+blitzcc$+"Bin\blitzcc.exe "+Chr(34)+"-o test.exe "+path$+Chr(34)+Chr$(34)

	ExecFile(blitzcc$)
End Function


The blitzcc$ string needs to be global or it will open up the folder the BB is running from. I found that out.

EDIT: Information source: http://www.bettiesart.com/tc/ultrablitz/


Chalky(Posted 2007) [#18]
Hi Ked,

blitzcc$ does not need to be global since it is being passed to the function as a parameter. You also only need to enclose the command line arguments with chr$(34) (and sometimes the whole command line - as you said in an earlier post) if either contains spaces, since blitzcc.exe expects spaces to be delimiters. Having created the env variable the code I posted above now works correctly.

Devils problem is probably due to him not having the environment variable set up on his system.


bytecode77(Posted 2007) [#19]
hey, the environment variable is the final solution!
it works perfectly without any bugs at all!
thank you guys! :)

btw: it is 5 AM here. didnt know you were so active while i should be sleeping... ;D


ozzi789(Posted 2009) [#20]
Hi sorry for digging out this thread..

I just cant get this working

i took the code from Ked and it just wont work (b+ / vista)
what should i do?

i even set the blitzpath env still nothing i just get unable to open input file


thanks 4 ur help
ozzi


Warner(Posted 2009) [#21]
Does the input file exist? Where is it located? I think it should be placed in the same folder as his code.
[Edit]Maybe this helps?
ff = WriteFile("test.bb")
WriteLine ff, "cls"
WriteLine ff, "print " + Chr$(34) + "hello world" + Chr$(34)
WriteLine ff, "waitkey"
WriteLine ff, "end"
CloseFile ff

ExecFile Chr$(34) + "c:\program files\blitz3d\bin\blitzcc" + Chr$(34) + " " + Chr$(34) + CurrentDir$() + "test.bb" + Chr$(34)



ozzi789(Posted 2009) [#22]
if i test your code i get a "Linker Version Error" i mean WTH?
blitzcc.exe hates me

edit:
now im at home (Win XP SP3) and 1.46 B+


Warner(Posted 2009) [#23]
Never heard from that :/ Is that the exact error message you are receiving? Try looking it up in Google. You say ur using b+vista, is that BlitzPlus? I tested the above on Blitz3D under Vista.


ozzi789(Posted 2009) [#24]
ok its working now, i forgot so set blitzpath

so on xp works fine

but on vista it is just not working, guess its because UAC (user access conntroll thingy)

and yeah b+ is blitzplus :)

thnx 4 ur help


Warner(Posted 2009) [#25]
UAC may prevent the 'test.bb' file from being written. If you haven't saved the program it runs from c:\program files\blitz3d\tmp. Maybe it will work if you save the program in another folder?


ozzi789(Posted 2009) [#26]
dont know, my vista pc is at work so i cant really try it out now :)


why cant i use a direct path (D:\files\test.bb) on CompileToExe("D:\files\test.bb", blitzcc$)

it just wont work


Warner(Posted 2009) [#27]
I suppose it needs quotes, something like:
Chr$(34) + "d:\files\test.bb" + chr$(34)


ozzi789(Posted 2009) [#28]
its kinda late here, il just post the code it isnt much, maybe somebody finds the mistake
Include "guideexportinclude.bb"
AppTitle "EditWindow"
Global path$
config=OpenFile("config.ini")
bbpath$=ReadLine(config)

SetEnv "blitzpath",bbpath$

Global EditWindow
Global lblLabel0
Global chbCheckBox0
Global chbCheckBox
Global chbCheckBox2
Global tfdTextField0
Global lblLabel1
Global btnButton0
Global btnButton1
Global lblLabel2
Global compress
Global debugger
Global crexe
Global ready=0
Global tocompile$

Const GWL_WNDPROC         = (-4)
Const GWL_HINSTANCE       = (-6)
Const GWL_HWNDPARENT      = (-8)
Const GWL_STYLE           = (-16)
Const GWL_EXSTYLE         = (-20)
Const GWL_USERDATA        = (-21)
Const GWL_ID              = (-12)


Const WS_OVERLAPPED       = $00000000
Const WS_POPUP            = $80000000
Const WS_CHILD            = $40000000
Const WS_MINIMIZE         = $20000000
Const WS_VISIBLE          = $10000000
Const WS_DISABLED         = $08000000
Const WS_CLIPSIBLINGS     = $04000000
Const WS_CLIPCHILDREN     = $02000000
Const WS_MAXIMIZE         = $01000000
Const WS_CAPTION          = $00C00000
Const WS_BORDER           = $00800000
Const WS_DLGFRAME         = $00400000
Const WS_VSCROLL          = $00200000
Const WS_HSCROLL          = $00100000
Const WS_SYSMENU          = $00080000
Const WS_THICKFRAME       = $00040000
Const WS_GROUP            = $00020000
Const WS_TABSTOP          = $00010000

Const WS_MINIMIZEBOX      = $00020000
Const WS_MAXIMIZEBOX      = $00010000


EditWindow=CreateWindow("Ext Compiler",10,10,287,383,0,+1 +4)



ownhwnd = QueryObject(EditWindow, 1)

SetWindowLong(ownhwnd, GWL_STYLE, WS_VISIBLE Or WS_CLIPSIBLINGS Or WS_CLIPCHILDREN Or WS_BORDER Or WS_DLGFRAME Or WS_SYSMENU Or WS_MINIMIZEBOX)
HideGadget EditWindow
ShowGadget EditWindow

menu1 = CreateMenu(bbpath$, 1, WindowMenu(EditWindow))

UpdateWindowMenu EditWindow


InitAcceptFiles(GetActiveWindow())
AcceptFiles True 

	lblLabel0=CreateLabel("Ext Compiler",16,8,72,16,EditWindow,0)
		SetGadgetLayout lblLabel0,1,0,1,0
	chbCheckBox0=CreateButton("Compress with UPX",16,128,112,16,EditWindow,2)
		SetGadgetLayout chbCheckBox0,1,0,1,0
	chbCheckBox1=CreateButton("Compile with Debugger",16,152,126,16,EditWindow,2)
		SetGadgetLayout chbCheckBox1,1,0,1,0
	chbCheckBox2=CreateButton("Create EXE-File",16,176,96,16,EditWindow,2)
		SetGadgetLayout chbCheckBox2,1,0,1,0
	tfdTextField0=CreateTextField(136,216,96,20,EditWindow)
		;SetGadgetText tfdTextField0,"textfield"
		SetGadgetLayout tfdTextField0,1,0,1,0
	lblLabel1=CreateLabel("Enter Commandline",24,216,92,16,EditWindow,0)
		SetGadgetLayout lblLabel1,1,0,1,0
	btnButton0=CreateButton("Compile",40,296,64,24,EditWindow,1)
		SetGadgetLayout btnButton0,1,0,1,0
	btnButton1=CreateButton("Change output dir",136,176,96,16,EditWindow,1)
		SetGadgetLayout btnButton1,1,0,1,0
	lblLabel2=CreateLabel("Drag the bb file into this window.",24,32,158,16,EditWindow,0)
		SetGadgetLayout lblLabel2,1,0,1,0
	bbfilelabel=CreateLabel("-",24,56,196,20,EditWindow,3)
			sepLine0=CreateLine( "Settings",0,100,272,18,EditWindow,0)
			
			
;SetStatusText EditWindow,path$
;-mainloop--------------------------------------------------------------

Repeat


			If ready=0 DisableGadget(btnButton0)
			If ready=1 EnableGadget(btnButton0)
 			Local c = AcceptedFileCount()

   			For i= 0 To c-1
     			tocompile$=AcceptedFile(i)
	  			rightst$=Right(tocompile$,4)
	  			If Not Right(tocompile$,3)=".bb" Or rightst$=".txt" Or rightst$="bak1" Or rightst$="bak2"
					tocompile$="Only *.bb or *.txt files!"
					SetGadgetText(bbfilelabel,tocompile$)
					ready=0
	  			Else
					oldpos=1
					backslashpos=0
					succes=0
					Repeat
						backslashpos=Instr(tocompile$,"\",oldpos)
						If backslashpos=0 Then succes=1:Exit Else oldpos=backslashpos+1
					Forever
					If succes=1 Then  shorttocompile$=Mid(tocompile$,oldpos)
						SetGadgetText(bbfilelabel,"-"+shorttocompile$)
						ready=1
				EndIf  
   			Next


	id=WaitEvent()
	Select id
		Case $401									; interacted with gadget
			DoGadgetAction( EventSource() )
		Case $803									; close gadget
			Exit
	End Select
Forever


;-gadget actions--------------------------------------------------------

Function DoGadgetAction( gadget )
	Select gadget
		Case chbCheckBox0	; user changed checkbox
		compress=compress+1
		If compress>1 Then compress=0
		Case chbCheckBox1	; user changed checkbox
		debugger=debugger+1
		If debugger>1 Then debugger=0
		Case chbCheckBox2	; user changed checkbox
		crexe=crexe+1
		If crexe>1 Then crexe=0
		Case tfdTextField0
			If EventData() = 13 Then	; user pressed return in textfield
			EndIf

		Case btnButton0	; user pressed button => Compile
		add$=""
		If ready=1
		add$=tocompile$
		If debugger=1 Then add$=add$+" -d"
		If crexe=1 Then add$=add$+" -o"


		CopyFile (tocompilefile$,CurrentDir()+"temp.bb")

		toto$=CurrentDir()+"temp.bb"
		CompileToExe(toto$,bbpath$)

		Else
		Notify ("This should never happen!")
		EndIf 

		Case btnButton1	; user pressed button => Change
		savetodir$=RequestDir()


	End Select
End Function


Function CompileToExe(path$, blitzcc$)
	blitzcc$ = Replace(blitzcc$, "/", "\")
	If Right(blitzcc$, 1) <> "\" Then blitzcc$ = blitzcc$ + "\"

	blitzcc$=Chr$(34)+blitzcc$+"Bin\blitzcc.exe "+Chr(34)+"-o test.exe "+path$+Chr(34)+Chr$(34)
	ExecFile(blitzcc$)
End Function






Warner(Posted 2009) [#29]
I think the quotes were wrong:
Function CompileToExe(path$, blitzcc$)
	blitzcc$ = Replace(blitzcc$, "/", "\")
	If Right(blitzcc$, 1) <> "\" Then blitzcc$ = blitzcc$ + "\"

	blitzcc$=Chr$(34) + blitzcc$ + "Bin\blitzcc.exe" + Chr$(34) + " -o test.exe " + Chr$(34) + path$ + Chr(34)
	ExecFile(blitzcc$)
End Function



ozzi789(Posted 2009) [#30]
omg it worked, big thnx :)