Monday, November 30, 2009

End Of Line (EOL) in Linux and Windows

The end of a line of text is marked by the EOL character. The EOL character differs between Windows and Linux.

In Linux, the EOL character is line feed (LF) character '\n'. Whereas in Windows, the EOL character is carriage return (CR) character '\r' followed by the line feed (LF) character '\n'.

For example, create a text file containing the following in both Linux (LinuxSampleTxtDocument.txt) and Windows (WindowsSampleTxtDocument.txt).

 this is first line
 this is second line
 this is third line

And dump the contents of both the files.
sh-3.1$ hexdump -cb LinuxSampleTxtDocument.txt
0000000   t   h   i   s       i   s       f   i   r   s   t       l   i
0000000 164 150 151 163 040 151 163 040 146 151 162 163 164 040 154 151
0000010   n   e  \n   t   h   i   s       i   s       s   e   c   o   n
0000010 156 145 012 164 150 151 163 040 151 163 040 163 145 143 157 156
0000020   d       l   i   n   e  \n   t   h   i   s       i   s       t
0000020 144 040 154 151 156 145 012 164 150 151 163 040 151 163 040 164
0000030   h   i   r   d       l   i   n   e  \n
0000030 150 151 162 144 040 154 151 156 145 012
000003a

sh-3.1$ hexdump -cb WindowsSampleTxtDocument.txt
0000000   t   h   i   s       i   s       f   i   r   s   t       l   i
0000000 164 150 151 163 040 151 163 040 146 151 162 163 164 040 154 151
0000010   n   e      \r  \n   t   h   i   s       i   s       s   e   c
0000010 156 145 040 015 012 164 150 151 163 040 151 163 040 163 145 143
0000020   o   n   d       l   i   n   e  \r  \n   t   h   i   s       i
0000020 157 156 144 040 154 151 156 145 015 012 164 150 151 163 040 151
0000030   s       t   h   i   r   d       l   i   n   e
0000030 163 040 164 150 151 162 144 040 154 151 156 145
000003c

Sunday, November 29, 2009

Mounting external hard disk

Once my external hard disk is not properly removed after use from Windows OS. And when I tried to access the hard drive using Linux (Ubuntu) OS, I faced the problem of failure in mounting the drive. Following is the snapshot of the diagnostic I received on connecting the external hard disk to Linux (Ubuntu) OS.


To fix the problem I forced the mount of external hard disk manually. The manual mount of external hard disk is done using the following commands in terminal.

sudo mount -t ntfs-3g /dev/sdb1 /media/disk/ -o force

And unmounted the external hard disk using the following command:

sudo umount /media/disk/


The problem got fixed. On subsequent access I found that the external hard disk is mounted automatically by the Linux (Ubuntu) OS.

Monday, October 12, 2009

Large executables for GCC built on Windows (cygwin/MinGW) - how to reduce the size?

Yes, the large executables for GCC built on Windows (cygwin/MinGW) can be reduced.

First we see why such a large executable?

Generally the size of executables built on Windows (cygwin/MinGW) would be larger than 20 MB (this metric is derived by experimenting with the build of GCC compiler for IA64). This is because of the presence of symbol information for debugging.

If the executable built is not for debugging, then the symbol information shall be stripped-off from the executable.

Strip-off symbol information from executable

The symbol information can be stripped-off from the executable (built on either cygwin or MinGW) by any of the following ways:

  1. Strip utility from binutils
  2. Set the environment variable "CFLAGS" with '-s'

1. Strip utility of binutils

The strip utility of binutils removes symbols from object file. The symbol information from the executable can be stripped-off as follows:
strip cc1.exe

Note: Assume the executable from which the symbol information is to be removed is "cc1.exe".

2. Set the environment variable "CFLAGS" with '-s'

The environment variable "CFLAGS" should be set with '-s' before the build of executable on cygwin/MinGW.

I.e. The environment variable CFLAGS can be set in the shell as follows:
export CFLAGS="-s"

Note: To check whether the enovironment variable CFLAGS is set or not, use the shell command "env". The shell command "env" would list of environment variables.

After stripping off the symbol information, the size of the executable would be reduced to ~7 MB (this metric is derived by experimenting with the build of GCC compiler for IA64).

Executable Compression

The size of the executable can be reduced further by executable compression. Refer executable compression.

The executable compression can be done using the executable packer UPX. UPX is a free and open source executable packer. For details on UPX, refer upx.sourceforge.net.

The executable compression can be done as follows (in windows command prompt):
upx cc1.exe

Note: Assume the executable to be compressed is "cc1.exe".

After compressing the executable, the executable size would be reduced to ~2 MB (this metric is derived by experimenting with the build of GCC compiler for IA64).