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.
- Open terminal and navigate to the directory where the source code file is stored.
- Compile using the following command:
g++ test.cpp
- Here g++ is the compiler used to compile our file. All C++ files can end with any of the following extension:
.cpp,.C,.cxx,.cc,.cp,CPP,.c++
- To execute the program use the following command:
./a.out
- 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.