link failure with -llapack

I can’t get a simple Lapack program to link:

pgf77 -llapack -lblas -lpgftnrtl solve.f
solve.f:
solve.o(.text+0x160): In function MAIN_': : undefined reference to dgesv_’
pgf77 -llapack -lblas -lpgftnrtl solve.f -#
solve.f:

/opt/pgi/linux86-64/7.0-4/bin/pgftn solve.f -opt 1 -x 119 0xa10000 -x 122 0x40 -x 123 0x1000 -x 127 4 -x 127 16 -x 19 0x400000 -x 28 0x40000 -x 70 0x8000 -x 122 1 -quad -x 59 4 -x 59 4 -tp k8-64e -x 51 0x20 -x 124 0x1401 -astype 0 -stdinc /opt/pgi/linux86-64/7.0-4/include:/usr/local/include:/usr/lib/gcc/x86_64-redhat-linux/3.4.6/include:/usr/lib/gcc/x86_64-redhat-linux/3.4.6/include:/usr/include -def unix -def __unix -def unix -def linux -def __linux -def linux -def __NO_MATH_INLINES -def x86_64 -def LONG_MAX=9223372036854775807L -def ‘SIZE_TYPE=unsigned long int’ -def ‘PTRDIFF_TYPE=long int’ -def __THROW= -def extension= -def amd64 -def SSE -def MMX -def SSE2 -def SSE3 -cmdline ‘+pgf77 solve.f -llapack -lblas -lpgftnrtl -#’ -x 124 1 -asm /tmp/pgf77KF4gSYdrRQdE.s
0 inform, 0 warnings, 0 severes, 0 fatal for solvelin
PGFTN/x86-64 Linux 7.0-4: compilation successful

/usr/bin/as /tmp/pgf77KF4gSYdrRQdE.s -o solve.o

/usr/bin/ld /usr/lib64/crt1.o /usr/lib64/crti.o /opt/pgi/linux86-64/7.0-4/lib/trace_init.o /usr/lib/gcc/x86_64-redhat-linux/3.4.6/crtbegin.o /opt/pgi/linux86-64/7.0-4/lib/pgfmain.o -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /opt/pgi/linux86-64/7.0-4/lib/pgi.ld -L/opt/pgi/linux86-64/7.0-4/lib -L/usr/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/3.4.6 -rpath /opt/pgi/linux86-64/7.0-4/lib -llapack -lblas -lpgftnrtl solve.o -lpgftnrtl -lnspgc -lpgc -lrt -lpthread -lm -lgcc -lc -lgcc /usr/lib/gcc/x86_64-redhat-linux/3.4.6/crtend.o /usr/lib64/crtn.o
solve.o(.text+0x160): In function MAIN_': : undefined reference to dgesv_’
pgf77-Fatal-linker completed with exit code 1

Unlinking /tmp/pgf77KF4gSYdrRQdE.s

ar -t /opt/pgi/linux86-64/7.0-4/lib/liblapack.a dgesv.o
dgesv.o

What am I missing here?

Hi Ross,

Please try: pgf77 solve.f -llapack -lblas

On linux, we use GNU linker, we pass exactly what is from the command line to preserve the order because sometimes the order matters. It turns out that the linker does not go back in command line and look for the libraries.

Hongyon