Tuesday, June 25, 2013

Compile and Run C Program using Visual Studio 2012 Express

You can compile and run a C program using Microsoft Visual Studio 2012 Express editions. This procedure has been tested using Visual Studio Express for Desktop running on Windows 7. Windows 8 users may try this procedure provided you install Visual Studio Express for Desktop.

There are two methods to run and compile a C program. The first method is using command line and the second method is using Visual Studio IDE.

Compile C Program in Command Line using VS Express


1. Select Start >> All Programs >> Microsoft Visual Studio 2012 >> Visual Studio Tools >> Developer Command Prompt for VS2012. See below.



2. Launch the "Developer Command Prompt for VS2012".

3. Navigate to the location where you wrote the program.

4. Compile the program using the command
cl <program_name.c>

5. The obj file and exe file will be created using the same program name.

Example:

I've wrote this simple program using notepad and saved into my document folder under cprogram1.c

Important: Please make sure that you save the file in program.c instead of program.c.txt. Notepad save everything in .txt extension by default. To avoid this problem, under the file explorer select Organize >> Folder and search option, select the view tab and clear the check on "Hide  extensions for known file types".

#include <stdio.h>

int main ( )
{
     printf ("This is a basic C program. \n");
     return 0;
}

I've launch the command prompt as follows


I run the program as follows


You cal also refer to this page from MSDN on compiling C program using command line.

Compile C Program in VS Express 2012 IDE


Step 1.
Launch Microsoft Visual Studio 2012 Express >> VS Express for Desktop.


Close the start page.

Step 2.
Select FILE >> New Project


You will see the dialog box as below


Select C++ and highlight the option Win32 Console Application. Change the name of the project if you prefer.


Click "OK".

Click "Next >"


Make sure that Console Application is selected. Clear all other options and checked "Empty project". As shown below:


Click "Finish"

The project screen is shown below:


Step 3
On the right hand side, under "Solution Explorer", right click "Source Files". Select Add >> New Item.


The dialog box is shown below


Change the file name from Source.cpp to any name with extension .c. In this example, I changed to Sample1Main.c



Step 4
Type your C program on the left pane.


Click "Save"

Step 5.
To compile the program click BUILD >> Build Solution


The output screen will show the following results


Please be reminded that the exe file is located under Projects\projectname\Debug\projectname.exe

Step 6.
To run the program you must open a command prompt and navigate to the file location since this is a console application.


Please note that besides the exe file, there is also a ilk file and pdb file.

Ilk file is Linker Input File, you can find explanation here.
Pdb file is Program Database file, you can find explanation here.

Additional Note: 
The disadvantage of using the IDE is that many files are created unnecessary. However, the advantage is that you can use the IDE for auto-complete and error detection.

Besides VS 2012 Express. You may try Eclipse or NetBeans since both IDE also support C program. Alternatively, you can download programmer's text editor such as Notepad++ for program editing and use the command line for compilation.

*****  

Install Lubuntu 13.04 on VirtualBox

Lubuntu is another version of Ubuntu using a light weight desktop environment. The desktop screen is not as appealing as Ubuntu but it can run on less memory or older computer.

Setting up Virtual Machine
On VirtualBox select "New".


 Enter the name of virtual machine. Click "Continue".


Set your memory allocation for this vm. Click "Continue".


Select an existing virtual hard drive or create a new one. Click "Create".


If you are creating a new virtual hard drive, select the hard drive file type. Select the default. Click "Continue".


Select "Dynamically allocated" and click "Continue".


Name the virtual hard drive and select the virtual hard drive size. Click "Create".

It is advisable to change the display setting of the virtual machine you just created. Right click your virtual machine and select "Settings". Click "Display" tab and change the settings as follows:


Installing Ubuntu
Click "Start" to start the virtual machine.


You need to select the start-up disk. Select the ISO image of Lubuntu 13.04. The system will launch Lubuntu.


Press Enter.


Move the cursor down to "Install Lubuntu" and press Enter.


Select the default language and click "Continue".


Check to download updates while installing install Flash and other third party software. You can also check to install MP3 plugin. Click "Continue".


Select "Erase disk and install Lubuntu" and click "Install Now".


Select your time zone. Click "Continue".


Select the default keyboard and click "Continue".


Create the username and set a new password. Click "Continue".


The installation begins.

Once the installation is completed you need to restart the system. The login screen is shown as below.



*Please remember to run system update for patches.

Install VirtualBox Guest Additions

Open Terminal application.
sudo apt-get install dkms
sudo apt-get install virtualbox-guest-additions

Alternatively, you could install the guest additions from the ISO image from VirtualBox. This is necessary if you have installed the latest version of VirtualBox.

Run the Lubuntu virtual machine and logged in. Under "Devices" Select "Install Guest Additions..". You can proceed from here.

If you encountered problem running the installation from the CD, click "Cancel" while trying to install the guest additions from the CD.

Open a terminal. Navigate to the CD folder under /media/<username>/VBOXADDITIONS.....

Run the file VBoxLinuxAdditions.run from the terminal using the command

$sudo ./VBoxLinuxAdditions.run 

After installing updates and guest additions, the system used up about 3.5GB of hard disk space which is 1GB less compared to Ubuntu or Linux Mint.

*****

Sunday, June 23, 2013

Install Linux Mint 15 MATE Desktop in VirtualBox

The following installation instruction is to install Linux Mint 15 MATE desktop 64-bit version to VirtualBox.

Setting up Virtual Machine
On VirtualBox select "New".


Enter the name of virtual machine. Click "Continue".


Set your memory allocation for this vm. Click "Continue".


Select an existing virtual hard drive or create a new one. Default is creating a new one. Click "Create".


If you are creating a new virtual hard drive, select the hard drive file type. Select the default. Click "Continue".


Select "Dynamically allocated" and click "Continue".


Name the virtual hard drive and select the virtual hard drive size. Click "Create".

You are back to the virtual machine manager screen.

In the mean time you can right click the virtual machine you've just created and change the setting. One recommended change is to increase the video RAM and enable 3D acceleration. See below.



Installing Ubuntu
Click "Start" to start the virtual machine.


You need to select the start-up disk. Select the ISO image of Linux Mint 15. The system will launch Linux Mint.


Click "Install Linux Mint"


Select the language of your choice. Click "Continue".


Click "Continue".


Select "Erase disk and install Linux Mint" and click "Install Now".


Select your time zone. Click "Continue".


Select the default keyboard and click "Continue".


Create the username and set a new password. Click "Continue".


The installation begins.



Once the installation is completed you need to restart the system. The login screen is shown as below.



*Please remember to run system update for patches.

VirtualBox Guest Additions

Please note that there is no need to install VirtualBox Guest Additions as the system already included the guest additions. You can use the following command to check if guest additions have been installed.

apt-cache policy virtualbox-guest-dkms
apt-cache policy virtualbox-guest-utils
apt-cache policy virtualbox-guest-X11



*****