How To Compile Pascal Code Using Console (Windows 7)

69
rate or flag
Facebook
Pin It

By heroix

Prologue

When I was at school we have been learning Pascal programming language and I faced one problem. Since it was school they didn't introduce us to compiling and other stuff "behind the scenes". We used poorly supported 4-6 years old IDE which is used even in national exams. So my problem was that technology progressed and now I had 64-bit Windows 7 as my operating system. Guess what? Our beloved IDE now didn't compile my code.

Environment Variables

So what to do?

So if you have faced the similar problem or you just want to learn how to compile without IDE here is what you should do. Go to freepascal.org download and install version of free pascal compiler you need. In my case I need to select Windows 64-bit (in AMD64/x86_64 category).

But sadly that is not all you need to do before compiling. Now we must set PATH so that your Windows knows where your compiler is. To do that Right Click on My Computer and select Properties -> Advanced System Settings (in left panel) -> Advanced Tab -> Environment Variables. Now if you don't see PATH variable like in this picture - you should add one by pressing new. And in variable value put something like this:

"C:\FPC\2.4.2\bin\i386-win32";

It depends on where you have installed your FPC and what version it is.This path should lead to the folder containing "fpc.exe" application. This thing is your compiler. If there was already something in the path variable you should separate them with semicolons.


Get this party started!

So now you can start compiling your .pas files. All you need to do is place them somewhere like "C:/pascal" so that the destination to them is short. Open your command line (console) by writing "cmd" in Start menu search (yeah, that Start in your bottom-left corner). To open your pascal files folder now write "cd C:/pascal". To compile something write "fpc yourProgram.pas". And to open your written program just write "yourProgram.exe".

For editing my programs I prefer notepad++, but you can use any simple text editor. So now you have learned basics of compiling your code, using console and setting the paths. Feel free to ask any questions in comments below.

Comments

someone 2 months ago

I did it just like that and it says no fpc command recognised

heroix profile image

heroix Hub Author 4 weeks ago

You sure your PATH is correct?

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    • No HTML is allowed in comments, but URLs will be hyperlinked
    • Comments are not for promoting your Hubs or other sites

    working