Saturday, November 8, 2008

Building xlslib on MSYS

I was looking for a way to create Excel spreadsheets without needing to resort to Perl's fantastic Spreadsheet::WriteExcel. I wanted something fast and light, so I went out looking and found the library xlslib. This appeared perfect, unfortunately no win32 DLL was available. This is the process to create one.

Follow the installation process for MSYS and MinGW. Install all recommended updates, it will not work otherwise. Install the latest version of libtool(Otherwise the make will fail since it can't find C:/msys/1.0/local/lib/libxls.0.dylib. This is because the old libtool does not know about dll as an alternative extension for dynamic libraries (.dylib is the default for MacOS X.))

Download xlslib and untar it to your MSYS home directory (usually in C:/msys/1.0/home/yourusername. Double click the MSYS icon to open a new session and do the following.

1. Add the following line to the top of the file in ~/xlslib/src/oledoc/oledoc.cpp.
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
2. Run the following commands.

~$ cd ~/xlslib
~/xlslib$ autoheader
~/xlslib$ touch AUTHORS ChangeLog stamp-h
~/xlslib$ aclocal
~/xlslib$ autoconf
~/xlslib$ touch config/
~/xlslib$ automake
~/xlslib$ rm config/
~/xlslib$ ./configure
~/xlslib$ make

3. The make will fail while building targets/test/mainC.c.

4. It will also fail to create a dll file. This can be remedied by running the following commands.

5. First modify libtool in ~/xlslib and change the line that says:
*cygwin*|*msys*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;;

*cygwin*|*msys*) output=`$echo $output` ;;

6. This keeps libtool from adding .exe to the end of the .dll file. Then run the following commands.

~/xlslib$ cd src
~/xlslib/src$ /bin/sh ../libtool --tag=CXX --mode=link g++ -g -O2 -shared -o xlslib.dll -rpath /usr/local/lib overnew.lo blank.lo cbridge.lo cell.lo colinfo.lo continue.lo crc.lo datast.lo docsumminfo.lo extformat.lo font.lo format.lo globalrec.lo index.lo label.lo merged.lo number.lo range.lo recdef.lo record.lo row.lo sheetrec.lo summinfo.lo unit.lo workbook.lo binfile.lo oledoc.lo olefs.lo oleprop.lo
~/xlslib/src$ strip -g xlslib.dll # (Optional) Strip debugging symbols.

5. You now have a working xlslib.dll!

1 comment:

misataka said...

It is the very interesting article.
When you succeed in build, please teach the version of libtool.