Understanding Programming Environments [Command Based Programming, non IDE based]
Many times I come across to a situation when a friend of mine would ask me for helping him/her to set up the programming environment. The real trouble that we all generally face is the ability to correlate the programming environment in different operating system.
I mean, when someone is told in college/workplace to code a C program
in “gedit” and compile it using “gcc” in Ubuntu (or any other Linux distro),
he might have have a hard time doing the same on his own laptop or system at
home, because he has Windows for gaming, off course.We all know that every
Linux distro out there sucks for gaming. Well, gaming apart, this article will
help those who have a hard time setting up the identical programming
environment on Windows as is on Linux.
<h3 style="text-align: left;">Compiler</h3>First things first. It is the compiler that will turn your code into something which is executable on the system. By executable, I mean “a.out” on Ubuntu, “a.exe” on Windows, “a.ipa” on an iPhone & “a.apk” on Android. The same C code will be compiled in a different “executable format” on different operating systems. That means a compiler is to support a variety of operating systems. For example, “GNU Compiler Collection” or simply “GCC” is available for both Ubuntu and Windows. GCC on both Ubuntu and Windows will have same “behind the scene” mechanism for code translation but will produce “a.out” for Ubuntu and “a.exe” for Windows. GCC comes pre-installed with Ubuntu, not with Windows (Windows and Apple both kind of hate open source software). You need to manually install “GCC” on Windows. The most common available one is “TDM GCC”. You can grab it here.
<h3 style="text-align: left;">Console</h3>Every operating system has a command based operating method which is hidden under its GUI. Earlier, when Graphical User Interfaces were not in the mainstream, one would have to manually type in each command to perform operations on a computer. To move any “abc” file you would have to type the command “MOVE C:/abc.txt C:/my/abc.txt”. Thanks to modern day GUI that “drag and drop” exists. Despite being a pain in the ass, Command line interface boast much more power than the GUI (you can hide a file with password protection and encryption using commands in Windows ). And that’s why every operating system provides a command based mechanism to operate the system. For Ubuntu (and other Linux distro) it’s called “Terminal” while in Windows it’s called “Command Prompt”. Whenever we install a new program, other than its regular GUI-based operation, it may also offer some “command based” action. For example, the “GCC” will be added to your Command Prompt only after you install GCC. If you are a computer science fellow, you should have a good hold over the command-based operation of at least any one OS.
<h3 style="text-align: left;">Text Editor</h3>You need something to code right? For coding, the default basic Text Editor will work, i.e Gedit for Ubuntu and Notepad for Windows. But I’ll suggest you having a more powerful text editor for coding. For Ubuntu, you can pick up different plugins available for Gedit, which will eventually make it more powerful or you can go for Vim Text Editor. For Windows, I’ll suggest Notepad++ or Atom. These text editors will provide features like auto-indentation, brace matching, color tags etc, making your code more readable and easy to understand.
<h3 style="text-align: left;">IDE</h3>As a beginner, it is highly recommended to use the above tools separately, so as to completely understand the process of program formation and compilation. That was how the programming took place earlier. But since we are at present, there’s some automation for that too. When the Compiler, Console & Text Editor are integrated into a single entity or software, we get an IDE (Integrated Development Environment). Here all the process becomes automatic. You don’t need to manually save 1.c file, then open Terminal to type “gcc 1.c” for compilation and finally run a.out program by typing “./a.out”. This 3 step process is completed by a single F9 button on the IDE. In addition to these 3 basic automation process, IDE also provides other tools like debugger etc. Just like compilers, there are different IDEs for different languages. Like Codeblocks, Turbo C++ for C or C++, inTellj for Java etc. And there are some really big and popular IDEs like Eclipse and Netbeans which support multiple languages like Java, C, php, Python etc.
<h3 style="text-align: left;">Let’s Code Then</h3>So, I think this is more than adequate information to properly understand the process of program compilation and formation on different platforms. So let’s now see how to compile and run the hello world program on Windows the way we would have done it on Ubuntu, that is through command based mode (No IDE used)
1. Make sure that you have installed “TDM GCC” installed on your Windows system.
2. In Ubuntu, we open Terminal and change our path to a desired folder using “cd” command. Command Prompt in Windows also has same “cd” command to change directory.
3. So create any new folder and get it’s path from its directory and copy it.
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><td style="text-align: center;"><td class="tr-caption" style="text-align: center;">Copy the path
4. Open command prompt(cmd) and type cd “<path>” and hit Enter. You can also type “cmd” in the search bar in File Explorer to automatically launch cmd in that path.
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><td><td class="tr-caption" style="font-size: 12.8px;">Use of CD command 5. The cmd will change its path to your described one.
6. Type “notepad 1.c” in cmd to open Notepad.
7. Type in hello world program.
8. Save the file as “1.c”
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><td><td class="tr-caption" style="font-size: 12.8px;">Hello World Program 9. Now in cmd type “gcc 1.c” to compile 1.c file
10. As told here gcc is a command that will translate or “compile” the c file to give an executable file, “a.out” on Ubuntu and “a.exe” on Windows.
11. Now run the executable using command “./a.out” on Ubuntu (Terminal) , “a” or “a.exe” on Windows (cmd).
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><td style="text-align: center;"><td class="tr-caption" style="text-align: center;">Compiling and executing the program
See how easy was that. I hope that this article has given you enough understanding of program compilation in different platforms using command based mode. Do drop your comments for suggestions and queries.