Skip to content

Latest commit

 

History

History
47 lines (30 loc) · 901 Bytes

compile guide.md

File metadata and controls

47 lines (30 loc) · 901 Bytes

How to Compile C/ C++

Compile C program using gcc compiler

  • Step 1. Compile the program.
gcc -o hello hello.c

This command will invoke the GNU C compiler to compile the file hello.c and output (-o) the result to an executable called hello.

  • Step 2. Execute the program.
./hello

This should result in the output

Hello World
  • Step 3. (Optional)

In order to avoid the ./ prefix each time a program is to be executed, insert the following as the last line in the file .profile (located in your home folder):

export `PATH=.:$PATH`

This step needs only to be done only once.

Compile C++ program using g++ compiler

  • Step 1. After you have saved the program file, type the command to compile:
g++ program.cc –o program
  • Step 2. To run the program, type:
./program