Version 53 of How to compile a TCL script into an EXE program

Updated 2018-09-28 13:11:17 by PeterLewerin

unperson I have downloaded the great Tclkit.exe and I have often started tcl programs by copying them and pasting them into tclkit.exe (it's a great system I find!)

Now, how do I make a Tcl program executable? Do I use Tclkit.exe?

Thanks!

(Excellent answer provided by Alex FW)


These methods vs a Starkit exe

Very important! Please note that in order to run a starkit exe app. needs the user to install Starkit in his/her machine. With either of these methods, no need to install anything: anyone using any Windows starting with Windows 98 can run the program. Click on the exe file and it runs before I can finish my sentence! Excellent!


How to compile a Tcl script and an icons directory into an exe (in Windows)

This is how to compile a tcl script + an icons directory (or any other directory) into an exe program. Let's assume for the sake of the example that we have a script called Birds.tcl located in c:\Birds. Please copy the commands but don't forget to make the necessary adaptations. These instructions work for **Windows.**


Using tclkit.exe:

Step 1

Copy tclkit.exe and sdx.kit into the directory where your Tcl source code file is. Ex: in c:\Birds

 TCLKit.exe can be downloaded from: http://www.equi4.com/tkdownload.html
 Sdx.kit can be downloaded from:  http://www.equi4.com/pub/sk/

---> You will now have in c:\Birds the following files:

 * Birds.tcl
 * tclkit.exe
 * sdx.kit

Step 2

Make a copy of the tclkit.exe into the directory where your TCL source code file is. Ex: in c:\Birds. Rename it to tclkit2.exe.

---> You will now have in c:\Birds the following files:

 * Birds.tcl
 * tclkit.exe
 * tclkit2.exe
 * sdx.kit

Step 3

At Start/Run, type the following command (make the necessary adaptations):

 c:\Birds\tclkit sdx.kit qwrap birds.tcl

([name redacted]: It seems that you need to be in the \Birds directory for this to work.)

You will then get the Tcl console. It will give a message: .. updates

Leave the console


Step 4

At Start/Run again type the following command (make the necessary adaptations):

 c:\Birds\tclkit sdx.kit unwrap birds.kit

You will then get the Tcl console. It will give a message: ... updates applied

Leave the console


Step 5

At this stage, you have to copy the icons directory into the app directory that has been created.

The directory created is for example:

c:\Birds\Birds.vfs\lib\app-Birds

Copy Icons into c:\Birds\Birds.vfs\lib\app-Birds and you will get:

c:\Birds\Birds.vfs\lib\app-Birds\Icons

(Make the necessary adaptations)


Step 6

At Start/Run again type the following command (make the necessary adaptations):

 c:\Birds\tclkit sdx.kit wrap birds.exe -runtime tclkit2.exe

Again you will then get the Tcl console. It will give a message: ... updates applied

Leave the console

---> That's all folks! **Your exe is ready. Congratulations! Have un!:)**

unperson Thanks Alex FW for your great help!


Using freewrap.exe

Step 1

Same as above, copy freewrap.exe into the directory where your Tcl source code file is.

 freewrap.exe can be downloaded from: http://sourceforge.net/projects/freewrap/

---> You will now have in c:\Birds the following files:

 * Birds.tcl
 * freewrap.exe

Step 2

At Start/Run, open the command prompt usually by typing **"cmd"**. Then type the following command (make the necessary adaptations):

 cd Birds
 freewrap birds.tcl

If you want to have custom icons in your app, then run the following command instead:

 freewrap birds.tcl -i my_custom_icon.ico

The default build of freewrap only supports the following icons:

  • 16x16 16 colors
  • 32x32 16 colors
  • 32x32 2 colors

Therefore your icon file should have the above icons.

---> That's all folks! **Your exe is ready.


For Apple and Unix users

 For Apple users: Do ... (instead of Start/Run)
 For Unix users: Do ... (instead of Start/Run)

Comments

"How can I compile Tcl type scripts into binary code" answers the question for many people. If you're starting from an appreciation of Tclkit, as apparently is the case, a Starpack might well be the most natural follow-up.

FW: Yep, the starpack page has the basic instructions.

FW: I helped him solve this off-wiki. I was gonna fix up his instructions as to how to make a starpack but I figured they would be out of place on this page, since they're the same as to make any Starkit. I won't be so brash as to delete them though.

unperson Well just for fun, try to find instructions as clear as the ones above on this wiki. By the way: no need to complete them: I have done it. Thanks! I appreciate your excellent explanations!

aa - How to create my first Starpack seems somewhat more clear to me than the instructions above, and has the advantage of not being limited to Windows.

unperson It works for you! Great then! Well it doesn't work for me and I am sure it doesn't work for a lot of people. To the contrary, FW's explanations works perfectly, A1! As the latins used to say: "de gustibus non disputandem" : we cannot discuss tastes; to each his own. I am sure explaining a different way to create an exe won't hurt anyone! :)

LV Robert, what do you mean when you say it doesn't work for me? Once specifics of a problem are reported, someone can hopefully make adjustments, clarifications, expansions appropriately.

unperson Pages dealing with the very same subject-matter are way too complex for me **from the start** and I'm sure they are for many people also. So, instead of spending hours deciphering such pages, I thought I'd write a simpler procedure based on Alex FW's excellent instructions FW.

This tclkit is a beauty!

Look into ezsdx - a small frontend for sdx

Zipguy 2013-12-30 You might also like to look at ezsdx - a small frontend for sdx which offers a few interesting features.:). It is Windows only, and is at v0.98b (and up). It does try to prevent people, who may be ignorant, from doing stupid things. It can:

  • Run xxx.tcl programs
  • QWrap/Unwrap xxx.tcl programs
  • Makes it easy to re-generate your xxx.kit file
  • Can even make xxx.exe

Also, it has extensive screenshots to explain how to go all the way, from a xxx.tcl, to a xxx.kit, to an xxx.exe.

Or you should have a look at Find and Run Program which does have some useful features for running things under Windows.


Adaptation of these procedures to Starpal

unperson Oh! And if you decide to adapt the instructions above for Apple or Unix Operating systems, please be my guest. I did not do it since I run Windows.

You could write 2 lines of text. Something like:

 For Apple users: Do ... (instead of Start/Run)
 For Unix users: Do ... (instead of Start/Run)

Zipguy 2013-12-30 - Starpal is old, and Windows only!


Unix and Linux are not the same

LES Perhaps it should be noted that Unix is not the same as Linux. It is very easy to find support to all things Tcl in Linux, but not so easy in the BSD Unix family.


See also: http://www.equi4.com/papers/skpaper4_2.html


slebetman: Added instructions for using freewrap since I find it is easier for me to answer the question "how to compile a TCL script into an EXE program" using it. Besides, the subject of this page is generic which makes freewrap a viable option.


Related to this page: there is a tcl2c compiler tclc.


martinal - 2010-04-21 10:51:14**

This page was really helpful. One thing I'd like to add is how to add more packages to your EXE. I searched around and found other pages that explained it. I thought I'd include it here so next time I need to do it, I'll be able to find it easier.

In step 5, you can also copy the library from the tcl\lib directory to the lib directory of the .vfs directory. Then just continue with step 6.

I'm amazed at how easy this page made it to create an EXE. Thanks for putting it together everyone.


nachancheno - 2010-05-04 12:19:01**

Thanks very much for this help, it was the only way that worked for me in order to generate exe program from tcl source.

But I have a little problem: the exe program does not take the custom icon, i.e., after the exe file generation, this assumes by default the icon of tclkit program, not the user's icon copied into Icons folder. I run via freewrap and the exe generates the icon I want but the exe doesn't work, i.e., the program remainds idle. Do I need an extra parameter via tclkit in order to force the exe generated by the process takes the user's icon?

Best regards,

Nachancheno


nachancheno - 2010-08-23 22:15:55**

Hi everybody. I had a problem generating the exe file when I need to use the Tk package in order to show graphics. The problem is that when I run the exe appears the message "Package tk not found" and the execution is stopped. When I run the program via interpreter, i.e., tclsh85.exe program.tcl the same problem didn't happen because I can continue and see the graphics. What instructions am I missing? Or what other parameters do I need to add to the tclkit program in order to avoid this problem? Thanks for your help in advance. Regards, Nachancheno

AM (24 august 2010) Try "package require Tk" instead - package names are case-sensitive. Also, if you are on Windows, you need to use tclkit.exe, not tclkitsh.exe, as the latter does not contain Tk by design (it is a "light" version of tclkit). For Linux the distinction is not quite necessary, as there you always have an ordinary console.


nachancheno - 2010-08-25 12:45:56**

I apologize because I did not very well explained. In my graphic tcl program I wrote "package require Tk". I don't know very well the tclkit program and I can't find info in the internet in order to customize it to include a package like Tk that is necessary in order to show graphics.

By the way, I'm not using the tclkit lite version, I'm using the hard and last version (8.5.2 for win of 32 bits) according with the link of this page, i.e., http://www.equi4.com/tkdownload.html

I am attaching the error message after I try to run a program that shows something graphic.

C:\Tcl\bin>planetGraffer2.exe

can't find package Tk

    while executing "package require Tk"
    (file "C:/Tcl/bin/planetGraffer2.exe/lib/app-planetGraffer2/planetGraffer2.tcl" line 5) invoked from within

"source C:/Tcl/bin/planetGraffer2.exe/lib/app-planetGraffer2/planetGraffer2.tcl"

    ("package ifneeded app-planetGraffer2 1.0" script) invoked from within

"package require app-planetGraffer2" (file "C:/Tcl/bin/planetGraffer2.exe/main.tcl" line 4)

I appreciate the help whoever person read this page can provide me.

Best regards,

Nachancheno

PT - A wiki is not a sensible place to request assistance. Post to the starkit mailing list ([email protected] [L1 ]) or to the comp.lang.tcl newsgroup [L2 ]

If your program cannot find Tk, then it is because your tclkit executable doesn't contain it. For Windows, there are two different tclkit binaries. tclkit.exe contains Tk and is linked as a graphical mode program. tclkitsh.exe does not contain Tk and is linked as a console mode program.

Tclkit lives at http://tclkit.googlecode.com/ so get recent binaries (8.5.8, 8.4.19) from there. If you need 8.6 pre-release binaries - look into http://www.patthoyts.tk/tclkit/

AM Try running tclkit - if it behaves as wish, it contains Tk and then something strange is happening. If not, it does not contain Tk and then the error message is quite correct.