180 likes | 293 Views
Building and Using Libraries. CISC/QCSE 810. Libraries. libraries exist for many common scientific tasks linear algebra – BLAS/ATLAS, LAPACK optimization – OPT++, TAO Fourier transforms – FFTW, FFTPACK image processing - Imagemagick data management – MySQL programming aids – Boost
E N D
Building and Using Libraries CISC/QCSE 810
Libraries • libraries exist for many common scientific tasks • linear algebra – BLAS/ATLAS, LAPACK • optimization – OPT++, TAO • Fourier transforms – FFTW, FFTPACK • image processing - Imagemagick • data management – MySQL • programming aids – Boost • GUIs – Microsoft, Xwindows • Tons more in C, or C++, or Java…
Example: Imagemagick • combination of library and executables • contains routines for image processing
Obtaining the Source • Libraries are binary files • Not transferable from OS to OS • Not necessarily optimized for a particular system • Typical to need to recompile on most Unix-based • Look for "source" or "tarball" ".tar.gz"
TAR files • TAR (Tape ARchive) files are most common Unix-based way to pass around directories of source code • Think "zip", but for unix • Unix utility with staggering number of options
Common TAR scenarios • Unpacking a gzipped tar file (.tar.gz) • tar xvzf <filename> • x – extract, v – verbose, z – gzipped, • f – file to act on • List files in a gzipped tar file • tar tvf <filename> • Create a tar file • tar cvf mfile.tar <files to include>
Imagemagick • Located at • www.imagemagick.org/script/install-source.hph#unix • Find the file • ImageMagick.tar.gz • Download it to your local drive • move to a directory without spaces in Cygwin e.g. /cygdrive/c • Untar • tar xvzf ImageMagick.tar.gz
Read the Readme! • There are standard steps many libraries use for building • ./configure • make • make test • make install • but that may not be the case for yours • always look for installation instructions
This will take awhile… • Configuring and compiling libraries can be a process of minutes to hours to overnight (hopefully not longer!) • Have something else to do…
Assuming it worked • If you successfully compiled and installed the library, you should now have • header file(s) (.h) somewhere accessible • a library file (.a) somewhere accessible • Those extensions are for C, C++ libraries in Unix
Next Step: building a program • You now want to try to link your own source files to the library • Start with a worked example from the library writers! • If that doesn't work, you know it's a configuration/linking problem
Imagemagick • Comes with a thumbnail-generating program as a model • Save as wand.c
Compiling against a library • Look for –I flags in gcc command • these add a search directory for "include" files • your source will have to "#include<library>" before you can use a library function • ImageMagick 'make install' puts header files in /usr/include and subdirectories
Linking against a library • Next step to is link the objects into an executable • Look for flags • -L: add a search directory for library files • -l: adds a library to the executable • -lpng links code to libpng.a library file • Most libraries found in /usr/lib or /usr/local/lib
Library Realities • Building a library can be one of the most frustrating computer experiences • you didn't write it • whoever did may not have had your system at hand (or in mind) • problems will tend to be at most esoteric level (compiler, OS, make, etc. behaving slightly differently than expected) • Library writers are experienced C coders, while you may not be
Hope is not lost • Google is your best friend • search for the exact error message • someone else has probably had it • search for your OS in the library's web site • most problems are often due to OS-specific issues • Be patient • a library could save you weeks to months of coding and testing; a few days to install isn't too much to ask
Your next task • Find a library that might be of use to you (FFT, image processing, genetic algorithms, optimization), and build their example code OR • Build some source code and link it into MATLAB (or Java)