Make your own free website on Tripod.com

Compiling C++ Program in Linux


Contents:

Logging In

You must login to a Linux Computer. To do so you must have a login name and a password. Ask your lab administrator to provide with you with your Login and Password:

Login:rohit

Password:

The password is not shown as you type it for privacy.

Back to top

Entering source code

On Logging in you are presented with a shell prompt:

rohit@localhost$_

Now type vi to launch the text editor:

rohit@localhost$vi

vi is a command mode text editor:

~
~
~
~
~

:

Press i or Insert key to start typing the program.

After you finish typing, Press Esc to leave the insert mode and get back to command mode. Now give the save command :w <filename.cpp>

Now exit the vi editor by giving the quit command :q

Back to top

Compiling the code

After returning to the shell, compile the program using g++ compiler

rohit@localhost$g++ filename.cpp

Back to top

Correcting any Errors

On compiling any errors are displayed with line numbers. On successful compilation you can move to the next section.

To edit the source code again, run the vi editor again:

rohit@localhost$vi filename.cpp

Correct the errors in the program and give the save command :w

Back to top

Running the program

On successful compilation, run the program by running the output file a.out:

rohit@localhost$./a.out

./ are required to indicate that the file is in the current directory.

Back to top

Obtaining the output

Once you are satisfied with your program's functioning, you can take its output by running it again and redirecting it to a file:

rohit@localhost$./a.out >output.txt

Now the output of your program is stored in output.txt which you can print or save to a floppy.

Back to top

Some tools for Windows users to try out linux :

Please see this page first!!

MingW Compiler - A compiler similar to gcc; for windowshttp://www.mingw.org/
Msys - A shell similar to linux, allowing you to practice writing an compiling programshttp://www.mingw.org/msys.shtml
Knoppix - A Linux distro that runs off the CD without need of installationhttp://www.knoppix.org/

Made By:

Rohit Rawat
ECE II Sem
Roll No 55
Back to homepage.