![gcc]()
This article aim to share a little bit of knowledge on how to compile c++ code by using gcc compiler. In case you never experience how to compile c++ code in linux environment, this article will guide you through install of gcc and compile your very first C++ program in Ubuntu. Here it go the steps:
1. Install Ubuntu build-essential package so that it install gcc compiler into the system. Use the following command to download the package.
$ sudo apt-get install build-essential
2. Create the C++ file. Let’s call the c++ file – “HelloWorld.cpp”. I am using vi to create the following C++ file. You may use your preference editor.
1 2 3 4 5 6 7 8 9
| #include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
return 0;
} |
3. Once the cpp file is saved and it’s ready to compile now by using g++. Use the following command to compile our very first cpp file now.
$ g++ HelloWorld.cpp -o HelloWorld
4. An executable HelloWorld is produced and ready to be executed by using the following command.
5. The output of the executable program is displayed as follow: