x32x01
ADMINISTRATOR
In our today's article we discuss about how we can run C and C++ programs in Kali Linux system.
Sometimes we counter with C and C++ programs, now we are using Kali Linux as primary installation then how to run them?
Well this is very easy. This tutorial is also going to be useful for other Debian based distributions like Ubuntu, Mint etc.
Without wasting valuable time let's get started.
Running C Programs in Kali Linux
First we need to have a C program in our Kali Linux system. Let's write it.
To write a C program we choose notepad++ in our Kali Linux system. Oh it's not comes with Kali Linux (Notepad++ supports Windows only) but we shows how we have installed Windows programs in Kali Linux.
After opening Notepad++ we wrote a simple 'hello world' script on C and save it with hello-world.c name on our desktop, as we can see in the following screenshot:
Now we just need to open our Terminal window in Kali Linux system and navigate to our Desktop directory by using cd command:
To run any C programs we need to have GCC in our Linux system. GCC is a C compiler for Linux or UNIX based system. It's comes pre-installed with Kali Linux but if we need to install or update gcc we can run following command in our terminal:
The screenshot of the command is following:
Let we are going to run our C program by using following command:
It will run as we can see in the following screenshot:
After running this command we can't see nothing output. No worry, it is not given any output now but created a a.out file in our current directory. We can see it by using ls command:
In the above screenshot we can see the a.out file. This is an executable file for Mac or Linux. If we use GCC in Windows system then it will create a exe file.
Now as we know this a.out file is executable we can execute this by using following command:
The screenshot is following. Here we successfully run our C program.
Then we got a file called hello and we run it using ./hello command.
Here we learned how we can run C programs in Kali Linux system.
Running C++ Programs in Kali Linux
Running C++ programming in Kali Linux is very similar to run C programs. Here in the place of GCC we need to use G++ compiler. To install/update G++ in our Kali Linux we ca use following command:
Then we can compile a C++ program. We have a C++ program ("Hello World!" file named hello.cpp for example).
Using G++ is very similar to GCC we can use -o flag to create another named file instead 'a.out'.
Then we can use following command to run our compiled file and get the output.
As we can see in the following screenshot:
This is how we can run C++ program in our Kali Linux system.
In this article we learned how we can run C and C++ programs in our Kali Linux or any other Linux distributation. Found this useful then make sure to follow us on Twitter and GitHub we posts updates there.
For any problem or question please leave a comment in the comment section. We will very happy to help and we always reply.
Well this is very easy. This tutorial is also going to be useful for other Debian based distributions like Ubuntu, Mint etc.
Without wasting valuable time let's get started.
Running C Programs in Kali Linux
First we need to have a C program in our Kali Linux system. Let's write it.
To write a C program we choose notepad++ in our Kali Linux system. Oh it's not comes with Kali Linux (Notepad++ supports Windows only) but we shows how we have installed Windows programs in Kali Linux.
After opening Notepad++ we wrote a simple 'hello world' script on C and save it with hello-world.c name on our desktop, as we can see in the following screenshot:
Code:
cd Desktop
To run any C programs we need to have GCC in our Linux system. GCC is a C compiler for Linux or UNIX based system. It's comes pre-installed with Kali Linux but if we need to install or update gcc we can run following command in our terminal:
Code:
sudo apt-get install gcc
The screenshot of the command is following:
Code:
gcc hello-world.c
It will run as we can see in the following screenshot:
Code:
ls
Now as we know this a.out file is executable we can execute this by using following command:
Code:
./a.out
The screenshot is following. Here we successfully run our C program.
Here we learned how we can run C programs in Kali Linux system.
Running C++ Programs in Kali Linux
Running C++ programming in Kali Linux is very similar to run C programs. Here in the place of GCC we need to use G++ compiler. To install/update G++ in our Kali Linux we ca use following command:
Code:
sudo apt-get install g++
Then we can compile a C++ program. We have a C++ program ("Hello World!" file named hello.cpp for example).
Using G++ is very similar to GCC we can use -o flag to create another named file instead 'a.out'.
Code:
g++ -o hello-world hello.cpp
Then we can use following command to run our compiled file and get the output.
Code:
./hello-world
As we can see in the following screenshot:
In this article we learned how we can run C and C++ programs in our Kali Linux or any other Linux distributation. Found this useful then make sure to follow us on Twitter and GitHub we posts updates there.
For any problem or question please leave a comment in the comment section. We will very happy to help and we always reply.