Compile a C++ Code in Linux

24 Jul 2014 by admin


The steps to compile a C++ program in Linux environment are essentially the same as the compiling in the C except for one diffrence. Instead of using "gcc" we use "g++" compiler to compile our code.Everything else remains the same.

  1. Open terminal and navigate to the directory where the source code file is stored.

  2. Compile using the following command:

  3. g++ test.cpp
  4. Here g++ is the compiler used to compile our file. All C++ files can end with any of the following extension:
  5. .cpp,.C,.cxx,.cc,.cp,CPP,.c++

  6. To execute the program use the following command:

  7. ./a.out
  8. Since we have not used -o flag to name the output file, it is by default named as a.out We can use all the flags in the same way we use in gcc.

Category: Programming

Comments

comments powered by Disqus