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
waits for you to press Enter, keeping the console window open so you can see the "Hello, World!" message.
- Add the following compiler directives after the
program
declaration.
Note
This line {$mode objfpc}{$H+}{$J-}
is a common setup for Free Pascal projects. It tells the compiler to use modern Object Pascal features and settings. It's good practice to include it.
Your final code would look as follows.
- Press Ctrl+S to save the code.
Compile & Run¶
Press F9 to compile and run the program.
You should be able to see a console window open with Hello, World!
displayed.
Lazarus IDE: Press the Enter key to exit the program, 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 the Command Prompt (CLI) doesn't work, here are a few things to check:
- Full Path: Try using the full path to
fpc.exe
(e.g.,C:\FPC\3.2.2\bin\i386-win32\fpc.exe HelloWorld.pas
). - PATH Variable: Ensure the directory containing
fpc.exe
(e.g.,C:\FPC\3.2.2\bin\i386-win32\
) is added to your system'sPATH
environment variable. You might need to restart your Command Prompt after updating PATH. - Lazarus IDE: If CLI is tricky, using the Lazarus IDE (as shown above) is often easier for beginners.
- VSCode/VSCodium Users: If you're using VSCode or VSCodium, make sure the Pascal extension by Alessandro Fragnani is set up correctly to find the compiler.
- OmniPascal: For a more integrated VSCode experience, you might also look into OmniPascal.
Linux CLI¶
On Linux, compile and run as follows.