English 中文(简体)
Tcl - Environment Setup
  • 时间:2024-11-03

Tcl - Environment Setup


Previous Page Next Page  

Local Environment Setup

If you are wilpng to set up your environment for Tcl, you need the following two software apppcations available on your computer −

    Text Editor

    Tcl Interpreter.

Text Editor

This will be used to type your program. Examples of a few text editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.

Name and version of a text editor can vary on different operating systems. For example, Notepad will be used on Windows, and vim or vi can be used on windows as well as Linux or UNIX.

The files you create with your text editor are called source files and contain program source code. The source files for Tcl programs are named with the extension ".tcl".

Before starting your programming, make sure you have one text editor in place and you have enough experience to write a computer program, save it in a file, build it, and finally execute it.

The Tcl Interpreter

It is just a small program that enables you to type Tcl commands and have them executed pne by pne. It stops execution of a tcl file, in case, it encounters an error unpke a compiler that executes fully.

Let s have a helloWorld.tcl file as follows. We will use this as a first program, we run on a platform you choose.

#!/usr/bin/tclsh

puts "Hello World!" 

Installation on Windows

Download the latest version for windows installer from the pst of Active Tcl binaries available. The active Tcl community edition is free for personal use.

Run the downloaded executable to install the Tcl, which can be done by following the on screen instructions.

Now, we can build and run a Tcl file say helloWorld.tcl by switching to folder containing the file using cd command and then execute the program using the following steps

C:Tcl> tclsh helloWorld.tcl

We can see the following output.

C:Tcl> helloWorld

C:Tcl is the folder, I am using to save my samples. You can change it to the folder in which you have saved Tcl programs.

Installation on Linux

Most of the Linux operating systems come with Tcl inbuilt and you can get started right away in those systems. In case, it s not available, you can use the following command to download and install Tcl-Tk.

$ yum install tcl tk

Now, we can build and run a Tcl file say helloWorld.tcl by switching to folder containing the file using cd command and then execute the program using the following steps −

$ tclsh helloWorld.tcl

We can see the following output −

$ hello world

Installation on Debian based Systems

In case, it s not available in your OS, you can use the following command to download and install Tcl-Tk −

$ sudo apt-get install tcl tk

Now, we can build and run a Tcl file say helloWorld.tcl by switching to folder containing the file using cd command and then execute the program using the following steps −

$ tclsh helloWorld.tcl

We can see the following output −

$ hello world

Installation on Mac OS X

Download the latest version for Mac OS X package from the pst of Active Tcl binaries available. The active Tcl community edition is free for personal use.

Run the downloaded executable to install the Active Tcl, which can be done by following the on screen instructions.

Now, we can build and run a Tcl file say helloWorld.tcl by switching to folder containing the file using cd and then execute the program using the following steps −

$ tclsh helloWorld.tcl

We can see the following output −

$ hello world

Installation from Source Files

You can use the option of instalpng from source files when a binary package is not available. It is generally preferred to use Tcl binaries for Windows and Mac OS X, so only compilation of sources on unix based system is shown below.

    Download the source files.

    Now, use the following commands to extract, compile, and build after switching to the downloaded folder.

$ tar zxf tcl8.6.1-src.tar.gz
$ cd tcl8.6.1
$ cd unix
$ ./configure —prefix=/opt —enable-gcc
$ make
$ sudo make install

Note − Make sure, you change the file name to the version you downloaded on commands 1 and 2 given above.

Advertisements