Saturday, 15 December 2012

setting up c++ compiler on linux

After reading this you will learn about 1-gcc compiler 2-how to compile code 3-how to execute c/c++ output file via terminal window(console)
.

This blog is about How to set up c/c++ compiler to work in a easy way with a bash script.

 How you set up to compile C++ programs depends on whether you are using Windows or Linux/Unix. This page describes the approach to use if you have a Linux/Unix machine. On both system , to compile a c/c++ code you need compiler , In GNU systems c/c++ compiler is called gcc . For more details how gcc works see manuals lot of documentations are available on web , or just type  in terminal  man gcc .(if you have gcc installed)
 so you will need to install gcc to go for code compilation. in terminal type install command sudo apt-get install gcc now let it finish . assuming gcc installed correctly ,follow steps below -
  • Create a folder (any name will go) in my case C++ is the name of folder.
  • In folder  C++ create a file named gcc edit it with normal text editor like gedit or leafpad or Kate.( Note-use normal text editor to do any kind of coding.do not use word-processors.) copy this code to the file  gcc- #/bin/sh
    echo compiling C++ using -ansi -pedantic-errors -Wall
    g++ -ansi -pedantic-errors -Wall $1 $2 $3                                                                 
     
  • Now save that file and make it executable from file properties -go to permission section if using nautilus or dolphin filemanager , or whatever the way you do that.
  • Now in C++ directory {where file gcc(bash script file) is saved} put the c/c++ code file.
  • now  to compile c/c++ code execute the gcc file it will ask you  to run in terminal if using gnome desktop environment . ( if using KDE to do hole process in a simple way open C++ directory in dolphin file manager and press F4 key on keyboard ,a mini terminal will open inside dolphin with same directory you are working , here C++ you need to type ./gcc  name of c/c++ code file  and Hit enter key  now compilation done with a output file ,to execute(check) output file type ./name of out file with extension)KDE users you finished.stop here rest is for GNOME guys.
  • now put the c/c++ code file to the C++ directory.
  •  open terminal and point to the directory  C++ .(you can use nautilus to do that if don't know how to jump form one directory to other, just go to C++ directory and select option open terminal here )
  •    and in terminal type ./gcc  name of c/c++ code file & Hit enter key . 
  •    compilation done a output file will appear on C++ directory   
  •  To execute that file type  ./name of out file with extension.
(note - we can do the same (compilation) with gcc commands. this blog  was written for easement of things for peoples who felling hard to learn commands and do mistakes while writing them in terminal.)

1 comment:

  1. This is why hi-fi and club sound systems always have more power than they need - so they don't have to run at full blast and stress the system.

    Pro Boosting

    ReplyDelete