Saturday, October 19, 2013

Install Ubuntu 13.10 on VirtualBox

Review

The latest release of Ubuntu 13.10 is here. I've installed it on a VirtualBox virtual machine running on a Mac OS host. This version is an improved version of 13.04. It is much more stable than the previous version.

Please note that Ubuntu is a resource intensive OS. Please ensure that your host OS is running on a powerful hardware. Please allocate more memory to the virtual machine. You can use Ubuntu 13.10 as your primary OS. Please refer to the installation instruction below.

Installation Notes

Setting up Virtual Machine
On VirtualBox select "New".


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


Set your memory allocation for this virtual machine. Click "Continue".


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


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. It is better to set a bigger disk space. Anyway, it will not occupy the hard disk until it is used. 

Click "Create". Then you are back to the virtual machine manager screen.


You may want to change some setting such as video memory and number of processor as shown below.




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


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


Click "Install Ubuntu"


Check the additional option if you want to download updates while installing and install third party software.  Click "Continue".


Select "Erase disk and install Ubuntu" 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".


Ubuntu One is a cloud service that allows you to store your data in the cloud. It also allows you to sync data across multiple mobile devices. In addition, you can stream music from the cloud service to your mobile device.

If you have want to have an Ubuntu One account, you can create a new account here. If you already have an account, please enter your credentials. Otherwise, click "Log In Later". 


The installation begins.


Once the installation is completed you need to restart the system. 



Software Updates and Management

Use the first icon on the top left corner as shown below to search for applications.


For software management enter "software" and the results is shown below.


To narrow the search, click "Filter Results" on the top right corner.


You can deselect the rest if you are only looking for Applications.


Software Update

Launch the icon named "Software Updater". The system will search for new updates and prompt you for installation when necessary.


Alternatively, you can use the following command

sudo apt-get update

You might want to set how the system perform software updates. In this case, launch the icon named "Software & Updates". Select "Updates".


I choose to check for update daily and prompt for updates immediately when there is new updates available.

Install New Software

To install new software, launch the application "Ubuntu Software Centre".

Search for the application you want and click install as shown below.



Install Guest Additions

You need to install dkms first as follows:

sudo apt-get install dkms

To install VirtualBox Guest Additions, you can use the command:

sudo apt-get install virtualbox-guest-additions-iso

I don't know how fast VBox update the guest additions in the Ubuntu software repository. If you just update to a new version of VBox, you might want to install the guest additions from VBox. 

To install from VBox, select Devices >> Install Guest Additions

The following screen will follow:


Click "Run"

The system will install the guest additions as follows:



Restart the vm and enjoy Ubuntu!


*****

Monday, September 23, 2013

Managing Podcast with iTunes 11.1

I've just upgraded iTunes 11.1. On the first look it appears that the features of managing individual podcast download may had been broken. After some exploration, I've discovered that there is a new way of managing podcast. Listed below is some of the new interface I've discovered. 

If you are using a list view for managing podcast, you'll be disappointed because you cannot manage individual podcast download here any more. You can only set the default podcast here.

To set default podcast, click settings.


and choose how you want the default podcast to be download.


Previously, to manage individual podcast you need to select each podcast on the list and click settings. In iTunes 11.1 there is another way for you to manage each podcast. Please note that your previous  podcast settings is not lost.

From the list view, you'll notice pages such as "My Podcasts" and "My Stations". To manage individual podcast select "My Podcasts".



Manage Podcast with My Podcast


The screen under My Podcasts is shown below:


On the left column is a list of individual podcast, on the right is the detailed list of episodes.

To manage how each podcast is downloaded click Settings on the right corner in the details pane.

You can manage how each podcast handles the download. On top of that you can determine the sort order and the play order.


Here are some more examples each with different settings:





My Complains
Although I did not experience any episode lost, I have some minor complains about the new iTunes. Under My Podcasts view, the list view on the left column did not sort my podcast in any order. It seems random. Some of my podcasts are split into two. As usual, iTunes is still very resource intensive and slow.

Other Problems   

There are some internet users experience lost of their podcast episodes after this upgrade. Personally, I did not experience such lost. Those who experience such lost mentioned the options of podcast sync as the cause. I did not turn on podcast sync.

I do not know what happen when you turn on podcast sync, but to turn it off go to preference and under "Store" uncheck "Sync podcast subscription and settings".


Apparently, to sync podcast subscripts you need to share details about your library with Apple.

Finally, I put up this post quickly because I was searching for solution with the podcast "problem". Please comment if you encounter different problem. I hope you find this article useful.

*****

Thursday, September 5, 2013

Create C Program with Dynamic Library using Xcode in Mac OS X

The following instructions is a simplified procedure to create a dynamic library. Please note that the actual implementation of dynamic library is very complex if the library is very large and multiple users or versions are involved. Please consult the Xcode user guide for more information.

Example

The following program is a complete program that uses some math functions:

#include <stdio.h>
#define PI 3.1415;
 
double CircleArea (double radius);
double CircleCircum (double radius);

double PowerOf2 (double number);
double PowerOf3 (double number);
 
int main ( )
{
 
 double r = 4.0;
 double n = 5.0;

 printf ("Radius %.2f, area is %.2f \n", r, CircleArea(r));
 printf ("Radius %.2f, circumference is %.2f \n", r, CircleCircum(r));
 printf ("%.2f to the power of 2 is %.2f \n", n, PowerOf2(n));
 printf ("%.2f to the power of 3 is %.2f \n", n, PowerOf3(n));

 return 0;

 
}
 
double CircleArea (double radius)
{
 return radius * radius * PI;
}

double CircleCircum (double radius)
{
 return 2 * radius * PI;
}
 

double PowerOf2 (double number)
{
 return number * number;
}

double PowerOf3 (double number)
{
 return number * number * number;
}


To create a dynamic library so that we could reuse all the custom math functions for other programs, we will split the function declaration into libmydymath.h. Then, we place the functions for circle in mydymath1.c and the power functions in mydymath2.c.

Note: You can have many C program file with just one header file such as lib.h, lib1.c, lib2.c ... and so on.


Create C Dynamic Library in Xcode

To create dynamic library in Xcode, please fellow the procedure:

On the "Welcome to Xcode" page, select "Create a new Xcode project".


Alternatively, you can use File >> New >> Project....



On the template page, select Framework & Libraries >> C/C++ Library. Click Next.


On the options page, enter the name of static library. In my case, it is mydymath. Make sure that the type is set to Dynamic. You may want to check "Use Automatic Reference Counting" if your library implementation contains pointers.


Library Naming Convention
The naming convention of a library package must be prefix with lib follow by the name of the library and the file must end with .dylib. Therefore a typical library should be named as libmydymath.dylib. However, you can ignore the prefix and the extension when using Xcode. In this case, the library name mydymath is alright.

Click Next. Then select the file location of your project. Click Create.

Once the project is created you will notice that the target is automatically name libmydymath.dylib.



To create the header file, select File >> New >> File...


On the template page, select "Header File" and click Next.


On the Save As dialog page, enter the name of header file libmydymath.h. Make sure the targets mydymath is checked as shown below. Click Create.



The header file for libmydymath.h is as follows:

#define PI 3.1415;
 
double CircleArea (double radius);
double CircleCircum (double radius);

double PowerOf2 (double number);
double PowerOf3 (double number);



To create the library implementation file, select File >> New >> File...

On the template page, select C File. Click Next.


On the dialog box, enter the first program as mydymath1.c as shown below. Click Create.


The program file for libmydymath1.c is as follows:

#include "libmydymath.h"
 
double CircleArea (double radius)
{
 return radius * radius * PI;
}

double CircleCircum (double radius)
{
 return 2 * radius * PI;
}


To create the next implementation use the same procedure as above.

The program file for libmydymath2.c is as follows:

#include "libmydymath.h"


double PowerOf2 (double number)
{
 return number * number;
}

double PowerOf3 (double number)
{
 return number * number * number;
}



To compile the library program, select Product >> Build:

You should have the following files in your project.



Create the Application Program

There are many ways to include a dynamic library into a projects.
Listed below are two simpler methods.

Method 1

Select File >> New >> Project.... Select Applications and Command Line Tool. Click Next.


On the options page enter the program name app1. Make sure that the type is set to C. You may want to check "Use Automatic Reference Counting" if your library implementation contains pointers. Click Next.



Enter the location of your file and click Create.

Include Library File
The fist method is to add all the files from the library project file. Select File >> Add Files to "app1"....


Navigate to your dynamic library project folder and select the entire folder of the dynamic library. Your project panel should be similar to the one shown below:



Method 2

Select File >> New >> Project.... Then select Applications and Command Line Tool. Click Next.


On the options page enter the program name app2. Make sure that the type is set to C. You may want to check "Use Automatic Reference Counting" if your library implementation contains pointers. Click Next.


Enter the location of your file and click Create.

Include Library File
The second method is to just copy the product (libmydymath.dylib) and header file (libmydymath.h). Open your dynamic library project and your application program. Stack them as shown below.


Then drag the file libmydymath.h and libmydymath.dylib to your current application project. Check "Copy items..." and "Add to targets". Click Finish.


Your application project should be similar to the screen below:



Select app2 project file (blue icon) and select Build Phases in the middle. See below.



On the lower right corner, click Add Build Phase and select Add Copy Files.


On the new Copy Files box, set Destination to Product Directory. Click the + sign and add the dynamic library libmydymath.dylib as shown below.



Create the Main Program

Create the following application program in main.c:

#include <stdio.h>
#include "libmydymath.h"
 
int main(int argc, const char * argv[] )
{
 
 double r = 4.0;
 double n = 5.0;

 printf ("Radius %.2f, area is %.2f \n", r, CircleArea(r));
 printf ("Radius %.2f, circumference is %.2f \n", r, CircleCircum(r));
 printf ("%.2f to the power of 2 is %.2f \n", n, PowerOf2(n));
 printf ("%.2f to the power of 3 is %.2f \n", n, PowerOf3(n));

 return 0;
 
}



Running The Application

To run the project, you can click the run button or select Product >> Run. The results should be shown as follow: 



Note:
  • Method 2 is much cleaner if your dynamic library is very large. If your library implementation is not big, first method is good enough.
  • The additional build phase step in method 2 is to copy the dynamic library and place the file together with the application binary file so that when the application runs, it could find the dynamic library.
  • If you intend to place the dynamic library at /usr/lib, please refer to the Xcode user guide.
  • Please note that this example does not involved in multiple versions of the same library. 
  • I've also not cover the actual packaging and distribution of the dynamic library itself. 
  • My final word is dynamic library implementation is a very complex subject, please conduct more research. 
*****