Next: , Up: Compiling and Linking   [Index]

2.2.1 Linking programs with the library

The library is installed as a single file, libgsl.a. A shared version of the library is also installed on systems that support shared libraries. The default location of these files is /usr/local/lib. If this directory is not on the standard search path of your linker you will also need to provide its location as a command line flag.

To link against the library you need to specify both the main library and a supporting CBLAS library, which provides standard basic linear algebra subroutines. A suitable CBLAS implementation is provided in the library libgslcblas.a if your system does not provide one. The following example shows how to link an application with the library,

$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm

The default library path for gcc searches /usr/local/lib automatically so the -L option can be omitted when GSL is installed in its default location.

The option -lm links with the system math library. On some systems it is not needed.3

For a tutorial introduction to the GNU C Compiler and related programs, see An Introduction to GCC (ISBN 0954161793).4



It is not needed on MacOS X.