reinh-bader / fgsl

Fortran interface to the GNU Scientific Library
https://doku.lrz.de/display/PUBLIC/FGSL+-+A+Fortran+interface+to+the+GNU+Scientific+Library
GNU General Public License v2.0
84 stars 23 forks source link

How to Install properly? #28

Closed JesusSave closed 3 years ago

JesusSave commented 4 years ago

Someone else install FGSL on my desktop, I can use FGSL in such an easy way:

gfortran -I/usr/include/fgsl bessel.f90 -lfgsl

However I installed FGSL on my Laptop, the same test does not work properly.

chen@jesuslovesme:~/Documents/numerical/fortran/fgsl$ gfortran -I/usr/include/fgsl bessel.f90 -lfgsl

Errors: /usr/bin/ld: /tmp/cceiCL9M.o: in function MAIN__': bessel.f90:(.text+0x1d): undefined reference togsl_sf_bessel_Kn' /usr/bin/ld: bessel.f90:(.text+0xc3): undefined reference to `gsl_sf_bessel_Knu' collect2: error: ld returned 1 exit status

The method I install is like this, doese there any problem?

export FC=gfortran export PKG_CONFIG_PATH=/usr/include/gsl/lib/pkgconfig export gsl_LIBS=/usr/include/gsl [ -f ./fgsl.tar.gz ] && echo "No need to download fgsl" || wget https://github.com/reinh-bader/fgsl/archive/v1.3.0.tar.gz -O fgsl.tar.gz mkdir -p fgsl_build cd fgsl_build tar -xzf ../fgsl.tar.gz --strip 1 autoreconf -fi ./configure CFLAGS="-Wall" FCFLAGS="-Wall" --prefix=${gsl_LIBS} make make check make install cd .. rm -rf fgsl_build

JesusSave commented 4 years ago

I don't why the two computers differ. However I find a universal way to compile:

To check the linkers first

pkg-config --libs fgsl

e.g. the linkers are printed

-L/usr/local/lib -lfgsl -lgsl -lgslcblas -lm

Then use the flags as a universe solution. gfortran -I/usr/include/fgsl example.f90 -lfgsl -lgsl -lgslcblas -lm

reinh-bader commented 3 years ago

Since you seem to have found the solution, I will close this ticket. Generally note that the gsl_LIBS need to contain the library linkage spec, not the include path.

Regards Reinhold