Hello, World!¶
How would you like to do your Hello World
?
Using the Lazarus IDE¶
Note
This section assumes you have correctly set up the following for your OS.
- The Free Pascal Compiler.
- The Lazarus IDE.
Create a Project¶
- Launch Lazarus IDE.
- Create a new Project.
- On the top menu bar, click
Project -> Simple Program -> OK
.
- On the top menu bar, click
- Save this Project.
- Click
Project -> Save Project
. - Save the Project file as
HelloWorld.lpi
in a new folder. - Note: Lazarus will save the main source file as
HelloWorld.lpr
.
- Click
You will see a simple program in the Source Editor window. The program
's name will be the same as the Project's name, as shown below.
Add Code¶
- Now insert the following lines between
begin
andend.
.
- The
WriteLn
function prints text on the console. - The
ReadLn
in the code prevents the console from being closed automatically.
- Add the following compiler directives after the
program
declaration.
Note
Make sure to have this line in all your Object Pascal codes.
{$mode objfpc}{$H+}{$J-}
Your final code would look as follows.
- Press Ctrl+S to save the code.
Compile & Run¶
Press F9 to run the compile and run the program.
You should be able to see a console open with Hello World
in it.
Press the Enter key to exit the progam, which also closes the console.
Using the CLI¶
Note
This section assumes you have correctly set up the Free Pascal Compiler and the fpc
is in your PATH
.
Create a .pas
File & Add Code¶
- Launch your favourite text editor
- Create a new file and put the following snippet in it.
- Save it as
HelloWorld.pas
.
Compile & Run¶
Windows CLI¶
On Windows, compile and run as follows.
Tip
If running fpc
from CLI doesn't work, try one of the following options.
- Supply the full path to the
fpc
. - Put the
fpc/bin/<architecture>
to yourPATH
then compile and run again. - Consider using Lazarus IDE instead.
- Are you a VSCode or VSCodium user? Make sure to setup Pascal by Allesandro Fragnani properly.
- Have you considered OmniPascal?
Linux CLI¶
On Linux, compile and run as follows.