This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using static libraries


Daniel Rohe schrieb:
> 
> I'd like to use the static version of gsl. what do I need to specify during compilation to
> do this?
> 
> Daniel

Hi Daniel!

This is the normal dynamic way (here a test application gsl_brent)

make gsl_brent
cc -c -I/opt/gsl-1.0/include -o gsl_brent.o gsl_brent.c
cc gsl_brent.o -o gsl_brent -L/opt/gsl-1.0/lib -lgsl -lgslcblas

The Makefile is (for gnu make):

GSL_PREFIX := $(shell gsl-config --prefix)

gsl_brent.o:	gsl_brent.c
	$(CC) -c -I$(GSL_PREFIX)/include -o $@ $<

gsl_brent:	gsl_brent.o
	$(CC) $< -o $@ -L$(GSL_PREFIX)/lib -lgsl -lgslcblas

(Do not forget to correct the tab-spaces, if using these lines)

To check, what is linked dynamically, use ldd:

ldd ./gsl_brent
        libgsl.so.0 => /opt/gsl-1.0/lib/libgsl.so.0 (0x40017000)
        libgslcblas.so.0 => /opt/gsl-1.0/lib/libgslcblas.so.0
(0x40180000)
        libc.so.6 => /lib/libc.so.6 (0x401c0000)
        libm.so.6 => /lib/libm.so.6 (0x402f5000)
        libgcc_s.so.1 => /opt/gcc-3.0.2/lib/libgcc_s.so.1 (0x40318000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

This was done on a linux system with gcc-3.0.2.

You can avoid dynamic linking generally by using -static, or in
particular to have static gsl-linking:

cc gsl_brent.o -o gsl_brent /opt/gsl-1.0/lib/libgsl.a
/opt/gsl-1.0/lib/libgslcblas.a

This should be the Makefile rule:

gsl_brent:	gsl_brent.o
	$(CC) $< -o $@ $(GSL_PREFIX)/lib/libgsl.a
$(GSL_PREFIX)/lib/libgslcblas.a

Make executes:

cc gsl_brent.o -o gsl_brent /opt/gsl-1.0/lib/libgsl.a
/opt/gsl-1.0/lib/libgslcblas.a

now ldd results:

ldd ./gsl_brent
        libc.so.6 => /lib/libc.so.6 (0x40024000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)


If you like to know more details, please ask.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]