Monday, December 3, 2007

The power of scripts


Today, i've got a strange(???) problem, like i have to make a new repository in our backup server, which should looks exactly like another folder tree in same machine, but my requirement is more specific, i don't want to copy the entire folder structure including its sub folders, i.e i need only the top level folders. At first i thought to write a C program for that, but it may take a few hours to write and test. so i decided to experiment with some VBscript. as i am using it for first time, i felt an odd feeling by seeing its syntax. but truly said, its the most powerful stuff for doing such kind of tasks. see my first ever script - to copy the top level folder structure of a repository.


' Get the source folder, subfolders

'create the folder structure in destination as in the src folder
'No subfolders support
'Authour : renjith.sreeATgmail.com
'

Set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Shell.Application")

srcFolderPath = InputBox("Enter the source folder","Select a folder","", 100, 100)

If srcFolderPath = "" Then
WScript.Echo "Invalid source folder, quiting..."
WScript.Quit()
End If

destFolderPath = InputBox("Enter the destination folder","Select a folder","", 100, 100)

If destFolderPath = "" Then
WScript.Echo "Invalid destination folder, quiting..."
WScript.Quit()
End If

' dest folder

set destFolder = objShell.NameSpace(destFolderPath)

Set srcFolder = objFSO.GetFolder(srcFolderPath)
Set colSubfolders = srcFolder.Subfolders

For Each objSubfolder in colSubfolders
destFolder.NewFolder (objSubfolder.Name)
Next

WScript.Echo "Folder creation completed."



undefined reference to `__gxx_personality_v0' !!!!


Stunned by this error message when i tried to compile a simple c++ test program under UNIX.
> gcc -o out atol.cpp
/tmp/cci91B6Q.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

actually i spend a half an hour to rectify this, but later only i found it as a programmers blooper ( shame on me ! )

Even if the gcc and g++ are from the GNU's compiler collection, there is a significant difference between them, at least for the context for using them.

The mistake was i tried to compile and link the a .cpp file by using the 'gcc' compiler. but the programs using the c++ object files should always be linked with g++ in order to supply the c++ libraries. My mistake was i tried to link the c++ object files to be linked with c libraries, and thus it showed 'Undefined reference'.

These undefined reference to the internal library functions like - __gxx_personality_v0.
when you see such an error, it is because you tried to link the C++ object files with gcc.

But there is another question, why the gcc worked in the first place?
It is like that - actually gcc will compile the c++ file, when it found a .cpp extension. but it cannot successfully link the generated object file(s)

These are very small things, but its enough to take away a good chunk of our time.