After spending hours searching the web for answers, I discovered there is a major lack of information on the topic. As such I felt I should save others time and effort by sharing what I discovered after some experimentation. I believe the steps in this tutorial may be similar to that used to compile other programming languages, although you will have to obtain and install the appropriate compilers for them to work.
I am writing these instructions specifically for the free linux based operating system, Ubuntu 10.04 (www.ubuntu.com), but they may be the same or similar for older versions of Ubuntu or other linux variants.
Before you begin this tutorial you will need to install the Free Pascal Compiler available through the Ubuntu Software Center or by using some alternative method. The version I used for this tutorial is 2.4.0-2.
1. Open a text editor and type in the following:
program Hello;
begin
Writeln('Hello');
Write('world');
Readln;
end.
2. Save the file as hello.pas and save it in location you can find relatively easily.
3. Open the terminal and change the directory location to that of the hello.pas file. To change directories you need to type "cd" then the directories; for example:
name@name-desktop:~$ cd Documents
name@name-desktop:~/Documents$
4. Next you need to compile the program. You do so by typing in the following:
name@name-desktop:~/Documents$ fpc hello.pas
It should quickly display something similar to the following:
Free Pascal Compiler version 2.4.0-2 [2010/03/06] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling hello.pas
Linking hello
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
6 lines compiled, 0.1 sec
Despite what the warning says, the file did compile and now you need to "install it" on your system.
5. If you look in the directory where the hello.pas file is located, you should now see a hello executable file and an object file called hello.o '" if you attempt to run the executable file you will notice that it doesn't work. Which is why you are now ready to do the following:
name@name-desktop:~/Documents$ sudo apt-get install hello
It will ask you to type in your password and after you do so, it should show something like this...
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
hello
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/33.3kB of archives.
After this operation, 659kB of additional disk space will be used.
Selecting previously deselected package hello.
(Reading database ... 267190 files and directories currently installed.)
Unpacking hello (from .../archives/hello_2.4-3_i386.deb) ...
Processing triggers for install-info ...
Processing triggers for man-db ...
Setting up hello (2.4-3) ...
6. Now you are ready to run your program! Type "hello" in the terminal and press enter. Congratulations! You should now see "Hello, world!" in the terminal.
To learn to program in Pascal, I highly recommend the tutorials from http://www.learn-programming.za.net/programming_pascal_learn01.html.
You can download the Free Pascal Compiler from their website http://freepascal.org/, but it's much easier to use the Ubuntu Software Center.
Published by Michelle Rogers
- Helpful Tips for Working with Fonts in Fonty Python Under Ubuntu LinuxTips for working with fonts in Fonty Python under Ubuntu Linux.
Ubuntu Netbook RemixIn this review we are going to discuss the computer that I have Ubuntu Netbook Remix installed on, the system requirements for Ubuntu Netbook Remix plus features of the operatin...
Ubuntu 10.04 Lucid Lynx Vs. Mac OS X 10.6 Snow LeopardThey're the latest, shiniest alternatives to Microsoft Windows out there. So how do they stack up against each other? Find out, in this battle of the big cats!- How Ubuntu 10.4 Lucid Lynx is More like Mac OS X Than EverIn both good ways and bad! Find out what new graphical shinies it's going to include, and how Mark Shuttleworth is trying to imitate Steve Jobs.
Using an Autorun.Inf File to Automate USB Flash Drive PromptsLearn how to create your own autorun.inf file that prompts users for input each time they insert a USB or other media device.
- E-Books: A New Medium for Your Writing
- Ubuntu Storms Linux Community
- Computer Programming Language Comparison
- How to Repair OpenOffice.Org On Ubuntu 10.4
- Ubuntu 10.04 Lucid Lynx Changes
- How to Install and Use a WG111T Wireless Adapter Under Ubuntu Linux
- Bisigi Offers Beautiful GNOME Themes for Your Ubuntu PC





2 Comments
Post a Commentthanks for your article. I have some experience with Turbo Pascal in MS operating system, and now I am new to Ubuntu Linux. I have been struggling to start Free Pascal in Ubuntu 10.04, with no success until I read your article today. I followed your example and was able to compile and run the "Hello world" program. Now I am a step closer to write simple programs in Free Pascal in Ubuntu. I have one immediate problem. In Turbo Pascal, I use , e.g. "writeln (lst, "print this.."); " , to send an output to the printer. But this command will not work in Free Pascal, giving me a compiling error, (compiler does not recognize 'lst'). I googled the problem but unable to find an answer. Can you please tell me how to send an output to a printer in Free Pascal for Ubuntu 10.04? Or can you direct me to a source for possible solution? Thanks again.
Please go to http://www.associatedcontent.com/article/5827420/6_easy_steps_to_compile_and_run_a_pascal.html?cat=15 to view the updated article.