From: jbjbowyer on
Hi there,

just wondering if anyone can help me on this since it's
doing_my_head_in. Essentially, I'm trying to link code to subroutines
of the HEALpix package, and also to lapack95. However, I keep getting
'undefined reference to <subroutine>.
Apologies for the lengthiness of it, but I've written most of my
procedure below (for the sake of detail):

--------------------------------------------------------------------------------
Okay, so initially the code was simply like:

PROGRAM TEST

use pix_tools

END PROGRAM

which compiled like:

frigga2:in jbowyer > gfortran TESTER.f90
In file TESTER.f90:3

use pix_tools
1
Fatal Error: Can't open module file 'pix_tools.mod' for reading at
(1): No such file or directory

This could be 'solved' by using

frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
TESTER.f90
frigga2:in jbowyer > gfortran -o TESTER TESTER.o -L/soft9/
Healpix_2.01/lib -lhealpix

and the code could then be tested using its subroutines i.e.

PROGRAM TEST

use pix_tools
integer :: nneigh, list(1:8), nside, ipix

nside = 4
ipix = 1

CALL neighbours_nest(nside, ipix, list, nneigh)
print*, nneigh
print*, list(1:nneigh) !list of pixels surrounding ipix at ns=4

END PROGRAM

I then needed to add lapack95 and ud_grade to the repertoire. This was
done one by one. First of all the code was

PROGRAM TEST

use udgrade_nr

END PROGRAM

The result was

frigga2:in jbowyer > gfortran TESTER.f90 In file TESTER.f90:4

use udgrade_nr
1
Fatal Error: Can't open module file 'udgrade_nr.mod' for reading at
(1): No such file or directory

as before. Attempting the solution to pix_tools yielded a correct
compilation

frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
TESTER.f90
frigga2:in jbowyer > gfortran -o TESTER TESTER.o -L/soft9/
Healpix_2.01/lib -lhealpix

As before, the code needed to be tested (as per the healpix facilities
manual), via

PROGRAM TEST

use udgrade_nr
integer :: nside
REAL, DIMENSION(:,:), ALLOCATABLE :: map_in, map_out
nside = 4
ALLOCATE(map_in(0:12*nside**2-1,1:1))
ALLOCATE(map_out(0:12*2*nside**2-1,1:1))

CALL udgrade_nest(map_low, nside, map_hi, 2*nside)

END PROGRAM

This then yielded

frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
TESTER.f90 In file TESTER.f90:20

CALL udgrade_nest(map_low, nside, map_hi, 2*nside)
1
Error: There is no specific subroutine for the generic
'udgrade_nest' at (1)


The .mod file actually refers to slightly differently-named
subroutines. So I changed the code accordingly to

PROGRAM TEST

use udgrade_nr
integer :: nside
REAL, DIMENSION(:,:), ALLOCATABLE :: map_in, map_out
nside = 4
ALLOCATE(map_in(0:12*nside**2-1,1:1))
ALLOCATE(map_out(0:12*2*nside**2-1,1:1))

CALL udgrade_nest_nd_d(map_low, nside, map_hi, 2*nside)

END PROGRAM

yielding

frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
TESTER.f90
frigga2:in jbowyer > gfortran -o TESTER TESTER.o -L/soft9/
Healpix_2.01/lib -lhealpix
TESTER.o: In function `MAIN__':
TESTER.f90:(.text+0x188): undefined reference to
`udgrade_nest_nd_d_'
collect2: ld returned 1 exit status


This problem has been left for a bit. Re-editing the code to call the
lapack files we have

PROGRAM TEST

use f95_lapack

END PROGRAM

This returns

frigga2:in jbowyer > gfortran TESTER.f90
In file TESTER.f90:5

use f95_lapack
1
Fatal Error: Can't open module file 'f95_lapack.mod' for reading at
(1): No such file or directory

If we use the split-command as before, we get

frigga2:in jbowyer > gfortran -c -I/usr/lib/lapack95_modules
TESTER.f90
In file TESTER.f90:5

use f95_lapack
1
Fatal Error: File 'f95_lapack.mod' opened at (1) is not a GFORTRAN
module file

So we can try to use f95

frigga2:in jbowyer > /soft9/bin/f95 -c -I/usr/lib/lapack95_modules
TESTER.f90
frigga2:in jbowyer > /soft9/bin/f95 -o TESTER TESTER.o

Which actually appears to have worked. Now let's test the code.

PROGRAM TEST

use f95_lapack

REAL, DIMENSION(1:6) :: b
REAL, DIMENSION(1:6,1:6) :: A
INTEGER :: i

DO i=1, SIZE(A,1)
A(i,i) = 1
b(i) = i
END DO

CALL LA_GESV ( A, b )
END PROGRAM

This returns:

frigga2:in jbowyer > /soft9/bin/f95 -c -I/usr/lib/lapack95_modules
TESTER.f90
frigga2:in jbowyer > /soft9/bin/f95 -o TESTER TESTER.o
TESTER.o: In function `main':
TESTER.016931.c:(.text+0x105): undefined reference to `sgesv1_f95_'
collect2: ld returned 1 exit status

---------------------------------------------------------------------------------------------------------------

The biggest puzzle for me is the issue with the module 'udgrade_nr',
which won't work even though it's .mod file is in the same directory
as that of 'pix_tools.mod', which does work.
I'm not sure how to alter the linkage, or whether I should edit the
makefile and re-build either or both programs, but any help would be
much appreciated.

Thanks in advance,

Jude

From: mecej4 on
jbjbowyer(a)googlemail.com wrote:

> Hi there,
>
> just wondering if anyone can help me on this since it's
> doing_my_head_in. Essentially, I'm trying to link code to subroutines
> of the HEALpix package, and also to lapack95. However, I keep getting
> 'undefined reference to <subroutine>.
> Apologies for the lengthiness of it, but I've written most of my
> procedure below (for the sake of detail):
>
> --------------------------------------------------------------------------------
< removed and uninteresting record of compilations and outputs>
> The biggest puzzle for me is the issue with the module 'udgrade_nr',
> which won't work even though it's .mod file is in the same directory
> as that of 'pix_tools.mod', which does work.
> I'm not sure how to alter the linkage, or whether I should edit the
> makefile and re-build either or both programs, but any help would be
> much appreciated.
>
> Thanks in advance,
>
> Jude

1. Modules are specific to a particular compiler. A module produced by
Compiler-A is, almost always, useless to Compiler-B, where A \= B.

2. Unless you use the source for Lapack and any other called subprograms
and compile everything with the same compiler, you will almost certainly
have problems.

3. If you use pre-compiled libraries, they must be certified for use with
your specific compiler; they could have been compiled by another compiler,
but they must be .mod and .obj compatible.

4. RTFM as to Fortran 9X modules and using them.

-- mecej4 (mecej4_at_operamail.com)
From: FX on
> gfortran -c -I/soft9/Healpix_2.01/include TESTER.f90
> gfortran -o TESTER TESTER.o -L/soft9/Healpix_2.01/lib -lhealpix

I'm not sure if you know, but you can do both at once:

gfortran -o TESTER -I/soft9/Healpix_2.01/include
-L/soft9/Healpix_2.01/lib -lhealpix TESTER.f90

> frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
> TESTER.f90 In file TESTER.f90:20
>
> CALL udgrade_nest(map_low, nside, map_hi, 2*nside)
> 1
> Error: There is no specific subroutine for the generic
> 'udgrade_nest' at (1)

This is, I think, the one message that you should try to understand
instead of working around it. It's telling that even though udgrade_nest
is defined (as an generic interface), it doesn't find any procedure in
that interface that corresponds to the argument types you're using here.
The question then is: are you using the right argument types, in the
right order?

> TESTER.o: In function `MAIN__':
> TESTER.f90:(.text+0x188): undefined reference to
> `udgrade_nest_nd_d_'

That means, not having found a udgrade_nest_nd_d routine defined, it
assumed it was an external, and then failed to find it at link-time. What
that means for you is that it was probably wrong to try and access
udgrade_nest_nd_d, which does not seem to exist and be public.

> Fatal Error: File 'f95_lapack.mod' opened at (1) is not a GFORTRAN
> module file
>
> So we can try to use f95

Without you telling us, we have no idea what compiler is invoked by the
command f95.

--
FX
From: Fei Liu on
jbjbowyer(a)googlemail.com wrote:
> Hi there,
>
> just wondering if anyone can help me on this since it's
> doing_my_head_in. Essentially, I'm trying to link code to subroutines
> of the HEALpix package, and also to lapack95. However, I keep getting
> 'undefined reference to <subroutine>.
> Apologies for the lengthiness of it, but I've written most of my
> procedure below (for the sake of detail):
>

Hello Jude, this message means that linker cannot locate a symbol name
from your library that it tries to link with. One good tool to diagnose
such problems on *nix system is 'nm' that will dump the symbols of an
object or a library file.

Fei
From: jbjbowyer on
On Apr 9, 6:21 pm, "FX" <coud...(a)alussinan.org> wrote:
> > frigga2:in jbowyer > gfortran -c -I/soft9/Healpix_2.01/include
> > TESTER.f90 In file TESTER.f90:20
>
> > CALL udgrade_nest(map_low, nside, map_hi, 2*nside)
> > 1
> > Error: There is no specific subroutine for the generic
> > 'udgrade_nest' at (1)
>
> This is, I think, the one message that you should try to understand
> instead of working around it. It's telling that even though udgrade_nest
> is defined (as an generic interface), it doesn't find any procedure in
> that interface that corresponds to the argument types you're using here.
> The question then is: are you using the right argument types, in the
> right order?

I'm certain that the argument types and order are correct; the code is
essentially
example code given in the healpix manual (although I've checked the
source too). udgrade_nr.f90 calls it like this, which looks fine (I've
checked the _inc files too):

private

public :: sub_udgrade_nest, udgrade_ring, udgrade_nest

interface udgrade_nest
module procedure udgrade_nest_1d_s, udgrade_nest_1d_d,
udgrade_nest_nd_s, udgrade_nest_nd_d
end interface

contains

include 'udgrade_s_inc.f90'
include 'udgrade_d_inc.f90'

It definitely exists and is public.

> Without you telling us, we have no idea what compiler is invoked by the
> command f95.

Oops, sorry! I've been using NAG. The code has libraries compiled from
each of NAG and gfortran.
Neither achieve compilation.

Thanks

Jude