Wednesday, July 31, 2013

C Programming in Mac OS X

Programming C in Mac OS X requires you to install Xcode. Fortunately, this development tool is available free. Go to your App Store and search for Xcode. Install Xcode by clicking on "Free" or "Install". Please note that the installation will take quite some time.



There are two methods of writing and compiling a C program. The first method is using Xcode and the second method is using command line. Both methods require installation of Xcode.

Using Command Line 

To use command line to compile a C program, we need to enable gcc (or llvm-gcc). Under Xcode, select Xcode >> Preferences,  click on the Downloads tab. You should see a line "Command Line Tools". Click on the install button on the right. Close Xcode when you are done.


You can use TextEdit to create a simple C program. Alternatively, you can also use vim from the Terminal.

Open the Terminal and navigate to the folder you would like to store the program. Create a new program as follows:

vim simple.c

Type the program as follows:
#include <stdio.h>

int main ()
{
     printf "Yet another C program! \n";
     return 0;
}

Note:
To get familiar with vim you can check out vim cheat sheet. My vim is configure to highlight C program, please follow the instructions here.

If you are not familiar with vim, use TextEdit. Please note that you need to select Format >> Make Plain Text. While you save the program, please make sure that you save as simple.c instead of simple.txt. (Although you can still compile under .txt provided you set the format as plain text, for clarity it is better to name the program .c)

Compile a simple program
At the command prompt use the following command 

gcc -Wall simple.c -o simple.out
  
Note:
gcc is the compiler name. Although Mac OS X uses llvm-gcc instead of gcc, you can still use the same gcc command.
-Wall indicate all warnings
-o specify output name, if you don't specify the output name the default is a.out

To run the program just run as follows:

./simple.out

Using Xcode

To Compile and run a c program using Xcode, launch Xcode, click to create a new project or select File >> New >> Project


Click "Create a new Xcode project".


Under OS X, select Application >> Command Line Tool. Click Next.


Enter the project name. Select type as "C". You can clear the option if you are not using any pointers. You can enable this option when you are doing advance C programming. Click Next.


Select the location you need to place the project. Click "Create".


Once the project is created, select main.c on the left hand panel. You'll notice that a simple program Hello World has been written for you. Change the program to your own program.



To compile and run the program, select Product >> Run. If the build is successful, you should see the output in the panel below.


Please note that if you are using Xcode to program C, beside main.c you will also be given a project file Simple.xcodeproj and a man page file (for command line tools) named Simple.1. You can remove .1 file however you must keep the project file.

*****



Wednesday, July 10, 2013

Install Mate Desktop with Compiz on Fedora 19

Update: For installation on Fedora 20, please refer to Install Mate Desktop with Compiz on Fedora 20.


This is the installation guide to install Mate Desktop with Compiz on top of existing GNOME Desktop or Cinnamon Desktop. If you prefer a clean Mate Desktop, please refer to the post Install Fedora 19 Mate Compiz Spin.

Actually,  I intended to use the Mate Compiz Spin as my main desktop environment, however, I encountered some minor but annoying issues. The main problem is after logging in, it takes a long while for the desktop to show. Other minor issues like lack of applications can be resolved by installing the additional applications manually.

After installing Mate Desktop on the existing GNOME/Cinnamon desktop environment, the desktop shows seconds after login. There is no lack of applications, in fact there are some duplicate applications, but this doesn't bothers me.

Please note that you need additional hard disk space to install Fedora 19 with Cinnamon and Mate desktop environment. It requires at least 6GB of disk space for the entire OS including software and desktop environment. For virtual machine users, please configure your virtual hard disk to have 15GB of disk space. The hard disk will take up 4GB of swap file and 500MB of boot sector, leaving you with 10.5GB of space. 6GB of them will be used to install various software including Cinnamon, Mate and Compiz.

For installation of Fedora 19, please refer to Installation Guide for Fedora 19. To install Fedora 19 on virtual machine, please refer to Install Fedora 19 on VirtualBox with Guest Additions.


Installing Mate Desktop

To install Mate desktop use the command:
sudo yum group install mate-desktop

Once the installation is complete, logout and login with Mate session as shown below.


You will get the desktop that is similar to GNOME 2.



Note:
Please note that you may have duplicate applications such as terminal, calculator and archive manager etc.

Installation of Compiz

For minimal install, use the command
sudo yum install compiz compiz-mate fusion-icon

For extended packages, use the command
sudo yum install compiz-plugins-main compiz-plugins-extra compiz-plugins-unsupported emerald-themes emerald-themes-extra

For a start, launch Compiz Fusion Icon from applications. You can launch 2 different scripts for different windows decorator. You can choose between Compiz Mate Gtk or Compiz Mate Emerald. Both scripts can be launch from Applications >> Accessories.


Configure Compiz Settings

There are many settings you can experiment with. The essentials are MATE compatibility and windows decorator.


Personally, I like 3D cube, so I uncheck Desktop wall and check Desktop Cube, Rotate Cube, Wobbly Windows and I would like to turn on additional windows function such as maximize, minimize and windows resize.

To rotate the cube, press Ctrl+Alt and use your mouse to turn the desktop slowly.




Configure Compiz at Startup

Please note that Compiz will not start automatically unless you launch them. To configure the desktop to launch Compiz automatically, please refer to the following instructions.

To permanently activate Compiz permanently, open dconf-editor under System Tools, go to org >> mate >> desktop >> session >> required-components. Under windowmanager, replace marco with 'compiz-mate-gtk' or 'compiz-mate-emerald'.



Alternatively, use the command:
gsettings set org.mate.session.required-components windowmanager compiz-mate-emerald

Replace compiz-mate-emerald with compiz-mate-gtk if you wish. If you did not set any of them, it will reset to marco.

Note:
Please note that installation instructions of Compiz are attributed to the Mate wiki page here.

*****

Tuesday, July 9, 2013

Install Fedora 19 using Netinstall

Update: For Fedora 20, refer to Install Fedora 20 using Netinstall.

This is the procedure for installing Fedora 19 using NetInstall method. For full installation of Fedora 19 on a computer, please refer to Installation Guide for Fedora 19. For installation of Fedora 19 on virtual machine, please refer to Install Fedora 19 on VirtualBox with Guest Additions. For Compiz fan, please refer to the post Install Fedora 19 Mate Compiz Spin.

This method allows you to download and install the latest software package from the repository, there is no need for software update after installation. Please note that it will take longer time for the installation to complete because the installer need to download every single package during installation.

I usually use this method to install minimal Fedora 19 on a virtual machine since it does not take up very much hard disk space and memory.

Creation of Media or Setting Up VirtualBox
For creating a bootable USB, please refer to the official Fedora documentation here. You can also refer to my post here on creating USB drive. For creating of VirtualBox environment please refer to my post mentioned earlier. Depending on what you are installing, the configuration on virtual machine is different depending on the software packages you choose. For minimal install, 1GB of RAM with 4GB disk space is more than enough. The total disk space for minimal install is usually less than 1GB.


Installing Fedora 19

Start your computer. You might need to press extra key at the beginning so that you can boot Fedora 19 Netinstall iso from USB drive. For virtual machine user, just click start.

Once you've bootup Fedora 19, it will bring you straight to the installation screen.


Select the language and make sure you check Set keyboard to default layout for selected language.


On the installation summary, you'll notice that there is a warning sign on installation destination. Unlike other installation you have addition option to choose installation source and software selection. Leave the installation source to the closest mirror. Click SOFTWARE SELECTION.


Under software selection, you have the choice of installing different type of desktop environment or basic desktop. You can also install packages only for servers. Only the right hand side, you can select additional software packages. In this case, I choose Minimal Install. Click Done when ready.


Please note that you need to confirm the installation target drive. Click on INSTALLATION DESTINATION.


Since I am using virtual machine. There is only one hard disk which is checked already. If you have more than one hard disk, click to select the disk you want to configure. Click Done on the top left corner.


In this dialog box, you can choose to let the system configure the partition for you. You just need to specify the partition scheme. You can also configure the partition manually. Click Continue


You will be shown the Configuration Summary. Review the summary page and change any setting such as time zone or keyboard. Click Begin Installation when ready.


Once the installation starts, in the meantime, you can set the root password and add user. Click ROOT PASSWORD.


Enter the root password and click Done when ready. Click USER CREATION.


Enter the user name and set the user password. Make sure you check Make this user administrator. Click Done when ready. 


Wait for the installation to complete.


Click Reboot on the lower right corner when installation is complete. The login screen is shown below:


There is no need to update the computer since all the latest software are downloaded from the server. However, you might want to install addition software. Please refer to Fedora 19 Post Installation Software Configuration Guide.

Note:
Although this procedure show a minimal install using netinstall, you can configure any software packages you want during the pre-installation stage. Please be aware that depending on your bandwidth and the software packages you choose, it may take a long time to complete the installation if you choose to install many software. 


***** 

Monday, July 8, 2013

Install Fedora 19 Mate Compiz Spin

The following guide contains the installation procedure for Fedora 19 Mate Compiz Spin. This procedure was tested on a HP laptop with dual core AMD processor and 4GB of RAM using a USB external hard disk. I boot Fedora 19 from a USB stick and install the entire OS on an external (USB) hard disk. Depending on your hardware, it is not advisable to install Mate Compiz spin in a virtual machine if your hardware could not support it.

For installation of original Fedora 19, please refer to Installation Guide for Fedora 19. For installing fedora 19 on virtual machine, please refer to Install Fedora 19 on VirtualBox with Guest Additions. For netinstall, refer to Install Fedora 19 using Netinstall.

Creation of Boot Media

You can download the Mate Compiz Spin from here. You can explore other custom spins here.

The procedure on creating bootable USB can be found on the official Fedora documentation here. For details of creating a bootable USB drive, please refer to my post here on creating USB drive.


Installing Fedora 19 Mate Compiz Spin

Start your computer. You might need to press extra key at the beginning so that you can boot Fedora 19 from USB drive. In my case, a HP laptop, I need to press Esc and then F9. Most other computer uses F9 or F10 or F11. Please refer to the user guide of your computer.

Once you've bootup Fedora 19 Mate, the dekstop is shown below.


Click Install to Hard Drive. The first screen of installation wizard is shown below.


Select the language and make sure you check Set keyboard to default layout for selected language.


On the installation summary, you'll notice that there is a warning sign on installation destination. You need to confirm the installation target drive. Click on INSTALLATION DESTINATION.


There are 2 disk available. I will be installing Fedora 19 on WD1600JS. This is an external USB hard disk. Click to select the disk you want to configure. Click Done on the top left corner.


In this dialog box, you can choose to let the system configure the partition for you, you just need to specify the partition scheme. You can also configure the partition manually. I usually configure partitions manually when installing on a physical machine. Click Continue. (For new Linux users who want to know more about Linux partitions, please refer to my post Linux Partitions)


In this summary screen for manual partition, click + on the lower left corner to create a new partition. The first partition is the boot partition. 500MB is sufficient.


The next partition is swap partition. The recommend size for swap file is two times of your system RAM. However, due to RAM size getting larger and swap is seldom utilized. It is recommended to give the swap file 4GB of space, even if you have 16GB of RAM.


The last partiton is the root partition, you can use the entire free disk space to allocate to the root partition. Leave the capacity blank.


The summary of partition is as follows:


Click Done when you complete your configuration. The next dialog box shows the summary of all your actions.


Click Accept Changes to commit the changes. You will be shown the Configuration Summary.


Review the summary page and change any setting such as time zone or keyboard. Click Begin Installation.


Once the installation starts, in the meantime, you can set the root password and add user. Click ROOT PASSWORD.


Enter the root password and click Done when ready. Click USER CREATION.


Enter the user name and set the user password. Make sure you check Make this user administrator. Click Done when ready. 


Wait for the installation to complete.


Click Quit on the lower right corner when installation is complete. You can reboot the system. The login screen:


The desktop is shown as below:




Updating the System
Click System >> Administration >> Yum Extender. There should be list of updates if your system is not updated. Make sure you select the option Updates.



Use the following command to update the system

sudo yum update

Once the update is complete, restart the machine. You need to restart the system if you've just update a new kernel.

After updating the system, you might want to install addition software. Please note that this spin does not includes Firefox and LibreOffice. You might need to manually install it.

To install Firefox, use the command:

sudo yum install -y firefox

To install LibreOffice, use the command:

 yum group install -y libreoffice

Alternatively, you might  just want to install some basic applications. Use the following command for each applications:

yum install -y libreoffice-writer
yum install -y libreoffice-calc
yum install -y libreoffice-draw
yum install -y libreoffice-impress
yum install -y libreoffice-base
yum install -y libreoffice-math
yum install -y libreoffice-graphicfilter
yum install -y libreoffice-emailmerge

For addition software configuration, please refer to Fedora 19 Post Installation Software Configuration Guide

Configuring Compiz
Launch CompizConfig Settings Manager from System >> Preference.


There are many configuration option depending on your preference. I turn on Mate Compatibility, Desktop Cube, Rotate Cube and Wobbly Windows.

Activation of Compiz
To activate compiz, Applications >> Accessories >> Compiz Mate GTK or Compiz Mate Emerald

Alternatively, use the command
compiz --replace

To rotate cube, press Ctrl+Alt while use your mouse to turn the cube slowly.





To permanently activate Compiz permanently, open dconf-editor, go to org >> mate >> desktop >> session >> required-components. Under windowmanager, replace marco with 'compiz-mate-gtk' or 'compiz-mate-emerald'.



Alternatively, use the command:
gsettings set org.mate.session.required-components windowmanager compiz-mate-emerald

Replace compiz-mate-emerald with compiz-mate-gtk if you wish. If you did not set any of them, it reset to marco.
  
Note: Unfortunately, I could not screen print the rotating cube, as the mate desktop screen print function is not working. I manage to screen capture the installation screen using virtual machine.

Note (update 7/10):
Although I like to use this spin, however, I find that the desktop took a long while to appear after login. In additions, it lacks a lot of software which you need to install manually. I decided to install Mate and Compiz on an existing Fedora 19 GNOME/Cinnamon environment. I prefer this method since I do not need to install additional applications. Duplication of applications doesn't bother me.

For users who prefer a clean desktop environment, please stick to this spin. For users who do not mind having bloated software you can refer to my post Install Mate Desktop with Compiz on Fedora 19. Please note that it might take 6-7GB for the entire OS and software. 

*****