Japanese version is not available currently. If you want it, please contact me.

Building Math Libs for Fortran/Linux

In the world of Linux, there are plenty of programs and libraries for scientific calculation. For example, with Debian/GNU distribution package, full feature of LAPACK (ja mirror) is provided in a binary form, with which you can solve various linear algebra problems with Fortran.

I had been very happy with it, but recently, I became to need another popular libraries, SLATEC (ja mirror) and SPARSE (ja mirror) for my work. The former contains various special functions, and the latter does the routines to solve the linear equations with sparse matrix. Unfortunately, these have not been included in Debian yet, so I managed to build them and write down the sequence here.


My environment before this job is Debian/GNU 2.0(hamm) on Pentium Pro PC. Installed packages used are gcc (or egcc) and g77. (I greatly appreciate the exertion of package maintainers!)

Recently, I heard that slatec library will also be included in the next version (slink) of Debian. Wow! :-).
(Added Jan 2000: Yes, debian now has its own slatec package, and it seems better than that built with the following procedure. Even if you're not the debian user, you can get the slatec_4.1-2.tar.gz from source package directory and make the library.)

In this document (and patches), libraries are built as static ones. This is because that my programs using these libs are rather special so that the shared lib is not so effective. If you want to make shared ones, refer to the docs such as GCC-HOWTO. Maybe you will have to compile each source with -fPIC, and to specify a soname when you archive the library.

Netlib and its mirrors

All of source archives used in this document are freely available at Netlib. Netlib (http://www.netlib.org) is a collection of mathematical software, papers, and databases. It has many mirror sites. The archives mentioned in this document are rather large in size, so you are strongly encouraged to use your nearest mirror site.

Build SLATEC Library

SLATEC is a well known library which includes over 1400 of useful routines for scientific calculations. See SLATEC Master Index page for introduction to SLATEC, and to search routines for your purpose.

(2001.07.28) Now you have slatec4linux.tgz file in Netlib distribution. You may want to use it instead of the following :-)

First of all, get sources from the Netlib (ja mirror). You need slatec_src.tar.Z, and optionally slatec_chk.tar.Z to check whether the library routines work correctly. You may also want to get useful documents in that directory.

For convenience, archives are made to be available from this site.

The third is the contents of the directory exept for those in previous two.

And the patch for IBM PC/Linux is here.

This patch includes:

After getting the sources, unpack them to some directory which has enough space. I recommend to expand slatec_src and slatec_chk in (builddir)/slatec/src/ and (builddir)/slatec/chk, respectively, to make the following sequence easier. i.e.:

	cd (builddir)	# copy archives in this directory.
	mkdir -p slatec/src slatec/chk
	zcat slatec_src.tar.Z | tar xvf - -C slatec/src
	zcat slatec_chk.tar.Z | tar xvf - -C slatec/chk

Next, apply a patch.

	cd (builddir)/slatec
	zcat ../slatec-4.1-egcs.diff.gz | patch -p1

Then you can "make lib" to build the library libslatec.a, and "make test" to check the validity of the results of compilation.

If all is done well, copy libslatec.a to somewhere (I recommend /usr/local/lib). When you want to link the lib with your program, do:

	g77 -o foo foo.o -L/usr/local/lib -lslatec

Instruction of each routine is written in the corresponding source code.

Build SPARSE Library

SPARSE is a library for handling large sparse linear systems. Of course it can solve various matrix problems (I'm using it for spline function routines).

Get the source archive. The sparse library is distributed at netlib (ja mirror), too. To build this lib, you need the whole contents of the above directory, so you may want to access there via ftp. addresses are:

You can also obtain the tarball of whole contents and my patch from this site:

Unpack the package and patch.

	zcat sparse-1.3.tar.gz | tar xvf -
	cd sparse
	zcat ../sparse-1.3-egcs-diff.gz | patch -p1

In this patch, fortran option is turned on in spconfig.h, so if you use this lib from c code (or want to change other preferences anyway), you should edit this file. See spdoc file for instruction.

When you can successfully extract files and patch them, just "make" the library libsparse.a and move it to proper directory (say, /usr/local/lib). Linking this library can be performed with:

	g77 -o foo foo.o -L/usr/local/lib -lsparse

Usage of routines are explained in spdoc file in the original archive.

Comments and suggestions are very welcome!
Nakano, Takeo nakano@apm.seikei.ac.jp
(last updated on 06 Aug 1998)

index (English)
index (japanese)