Powered by Blogger.

Tuesday, 24 January 2023

Tag:

How to installation c++ programming on linux

 

                        

    • Linux Installation: We will install the GNU GCC compiler on Linux. To install and work with the GCC compiler on your Linux machine, proceed according to below steps: 
      • You have to first run the below two commands from your Linux terminal window: 
sudo apt-get update
sudo apt-get install gcc
sudo apt-get install g++
  • This command will install the GCC compiler on your system. You may also run the below command: 
sudo apt-get install build-essential
  • This command will install all the libraries which are required to compile and run a C++ program. 
     
  • After completing the above step, you should check whether the GCC compiler is installed in your system correctly or not. To do this you have to run the below-given command from Linux terminal: 
g++ --version
  • If you have completed the above two steps without any errors, then your Linux environment is set up and ready to be used to compile C++ programs. In further steps, we will learn how to compile and run a C++ program on Linux using GCC compiler. 
     
  • Write your program in a text file and save it with any file name and.CPP extension. We have written a program to display “Hello World” and saved it in a file with the filename “helloworld.cpp” on desktop. 
     
  • Now you have to open the Linux terminal and move to the directory where you have saved your file. Then you have to run the below command to compile your file: 
g++ filename.cpp -o any-name
  • filename.cpp is the name of your source code file. In our case, the name is “helloworld.cpp” and any-name can be any name of your choice. This name will be assigned to the executable file which is created by the compiler after compilation. In our case, we choose any-name to be “hello”. 
    We will run the above command as: 
g++ helloworld.cpp -o hello
  • After executing the above command, you will see a new file is created automatically in the same directory where you have saved the source file and the name of this file is the name you chose as any-name
    Now to run your program you have to run the below command: 
./hello
  • This command will run your program in the terminal window.

About Code Tutorial

Hi, My Name is Hafeez. I am a webdesigner, blogspot developer and UI designer. I am a certified Themeforest top contributor and popular at JavaScript engineers. We have a team of professinal programmers, developers work together and make unique blogger templates.

0 comments:

Post a Comment