One of the benefits of Linux distros is the ability to easily run C and C++ programs from both the terminal and any IDEs that you choose to install. We'll go over a quick tutorial on how to run your first C/C++ program on your Ubuntu Shell™
First, we'll go ahead and open up a clean terminal session and cd into our home directory to be safe.
Then, input the following commands in succession:
sudo apt-get update
sudo apt-get install build-essential manpages-dev
This essentially ensures that you have all the necessary packages needed to run your C/C++ programs. Next, we'll input the commands:
where is gcc
where is g++
to make sure that we have both the C and C++ compilers, respectively, installed.
Now we'll begin writing our first C program! For our text editor, we'll use VIM, a native text editor for the Linux terminal. You can try writing anything you'd like, however I wrote a simple program that outputs "Hello World!" to the terminal whenever the program is run.
Once you write your program, go ahead and input the following command:
gcc *file name* *executable file name*
where *file name* is the name of your C file and *executable file name* is the name that you'd like for your executable.
In my case, I named my file a.out, however you can name it whatever you like. The executable should be in your home directory now, so now all you would need to do to execute your file would be to input the command:
./*executable name*
Congratulations! You've written your first C program, and this is only the first step towards being able to create intricate programs using the baseline tools that Ubuntu provides.
Comments
0 comments
Please sign in to leave a comment.