How to compile and run C/C++ code in Linux

How to compile and run C/C++ code in Linux
In case you have installed Linux on your system and need to compile and run C/C++ code in the Linux environment, you will need to install GNU Compiler Collection and a text editor. There are many text editors available and here's the Top 3 Open Source text editors for Linux.

To install GCC (GNU's Compiler Collection) 

Debian / Ubuntu based Distributions can use the following commands to install the compiler collection to compile and run C/C++ programs.

sudo apt-get update
sudo apt-get install build-essential manpages-dev

In case, you are using Fedora, RedHat or CentOS, you can use the yum command to install it.

yum groupinstall 'Development Tools'

How to compile and run C/C++ program

The next step is to create a C/C++ file using any text-editor. Open the text editor, type the code
 
How to compile and run C/C++ code in Linux
#include<stdio.h>
int main(void)
{
   printf("Hello World");
   return 0;
}

and save it under any name say hello.c

Now, you can use the gcc command to to compile the code you have just written.

gcc hello.c

To run the compiled file, type

./a.out 

How to compile and run C/C++ code in Linux

You have read how to compile and run C/C++ code in Linux. If you want to set up Debian in a virtual box: Installing Debian on Oracle VM Virtual Box [Windows 7 Host.

0 komentar:

Posting Komentar