How to compile C/C++ in Linux terminal.

 Hello everyone, in this post you will learn how to compile and run C or C++ programs in the Linux terminal. 

For this you will need GCC (in most cases it will already be installed in your system) if not you can: 

apt install gcc

Then open terminal in the folder where you have stored your C/C++ files.

Then type:

gcc -o <give a name without "<>" of course> <name of the file which you want to compile>

(If your program has any error it will be shown after you enter this command.)



Then you will see a new file of the name you have given will be created. Right click on that newly created file and click on "Properties" then click on "Permissions" tab and check mark "Allow executing file as program", Then close the window. On this step, you can use the "chmod +x <name of the the newly created file>"can also be used.

Now in the terminal type:

./<and the file's name of which you just changed the permission>

Your program should now run.



Comments

Popular Posts