How To Compile Pascal Code Using Console (Windows 7)

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 was also used in national exams. So my problem was that as technology progressed, 64-bit Windows 7 came to action and our beloved IDE now didn't compile a code on this new Operating System.

Environment Variables
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.

More by this Author

  • Notepad++ Compiler
    9

    Notepad++ is just a simple text editor with syntax highlighting. Personally I love it, but the drawback is that sometimes I want to compile and write code with the same tool. As you know Notepad++ has no built-in...


Comments 6 comments

someone 5 years ago

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


heroix profile image

heroix 4 years ago from Vilnius, Lithuania Author

You sure your PATH is correct?


Edzus 4 years ago

Hi,

I did all step by step, just changed C:/pascal folder to C:/PASKALS, when i typed fpc myfile.pas, consule said: "'fpc' is not recognized as an internal or external command,

operable program or batch file."

What goes wrong? In system settings i wrote like this C:\FPC\2.6.0\bin\i386-win32\ and named that value to FPC.


heroix profile image

heroix 3 years ago from Vilnius, Lithuania Author

You must have set an incorrect PATH variable. You can also try to restart your console, which sometimes might be a case.


Colin Tobing 3 years ago

It's helpful... thanks a lot man :D


Samuel Santos 2 years ago

I have the same problem which Edzus , to solve my problem i did!

in Enviroment System adding a new system variable click add button to create a new variable, name= FPC and value = C:\FPC\2.6.0\bin\i386-win32\ , and works!!!

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

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


    Click to Rate This Article
    working