How To configure C and C++ Development Environment in Linux ( CentOS / Fedora / Red Hat )

1- Install GNU C/C++ compiler and Essential tools to configure Development Environment:-

If  you have Internet connection and you using CentOS / Fedora / Red Hat then you use Yum Command to install GNU C/C++ compiler and Essential tools.

[root@localhost ~]# yum groupinstall ‘Development Tools’     

2-Check or Verify Installation 

These are the following command to display the version  and location of the compiler.

 [root@localhost ~]# rpm -qa gcc
gcc-4.4.7-11.el6.i686
[root@localhost ~]#

Or

 

[root@localhost ~]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
[root@localhost ~]# which gcc
/usr/bin/gcc
[root@localhost ~]# gcc –version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost ~]#

3- Compile and Run C/C++ test program on Linux Environment           

i- Create a file called test.c using a text Editor Such as vi, Emacs or Joe etc.

#include<stdio.h>
int main()
{
printf(“This is a Test program for GNU C Compiler\n”);
return 0;
}

Syntax for Compile

 gcc program-source-code.c -o executable-file -name

Syntax for  Run

./executable-file-name

Output of above test program

 

[root@localhost ~]# gcc test.c -o test1
[root@localhost ~]# ./test1
This is a Test program for GNU C Compiler

[root@localhost ~


ii-Create a file called test.cpp using a text Editor Such as vi, Emacs or Joe etc.

#include “iostream”
int main(void)
{
std::cout << “This is a Test C++ program.\n”;
return 0;
}

Syntax for Compile

 g++ program-source-code.cpp -o executable-file -name

Syntax for  Run

./executable-file-name

Output of above test program

[root@localhost ~]# g++ test2.cpp -o test3
[root@localhost ~]# ./test3

This is a Test C++ program.
[root@localhost ~]#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s