Question: I would like to understand the basics of how to write and execute a pascal program on Linux OS. Can you explain it with a simple example?
Answer: In this article, let us review very quickly how to write a basic Hello World pascal program and execute *.p or *.pas program on Linux or Unix OS.
1. Write a Hello World Pascal Program
Create the helloworld.p program using a Vim editor as shown below.
$ vim HelloWorld.p Program HelloWorld(output); begin writeln('Hello, world!'); end.
2. Make sure pascal compiler is installed on your system
Make sure pascal compiler is installed on your system as shown below.
$ whereis pc pc: /usr/bin/pc /usr/share/man/man1/pc.1.gz $ which pc /usr/bin/pc
Installing pascal compiler
If you don’t have pascal compiler, install it as shown below.
$ sudo apt-get install fp-compiler
3. Compile the pascal program.
Compile the HelloWorld.p which will create the HelloWorld executable.
$ pc HelloWorld.p Free Pascal Compiler version 2.2.2-8 [2009/01/08] for i386 Copyright (c) 1993-2008 by Florian Klaempfl Target OS: Linux for i386 Compiling HelloWorld.p Linking HelloWorld 4 lines compiled, 0.1 sec $ ls HelloWorld* HelloWorld.o HelloWorld.p
4. Execute the pascal program.
Execute by mentioning the program name.
$ ./HelloWorld Hello, world!
Get the Linux Sysadmin Course Now!