[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netCDF #UAT-411621]: getting undefined reference when compiling netCDF4.2 Fortran



Hi Steve,

> I have attached my config.log file,  from running configure in netCDF
> Fortran 4.2. Perhaps you can detect something.
> 
> I am still seeing errors like:
> 
> libtool: link: /home/skirby/ANDROID19/bin/arm-linux-androideabi-gfortran
> -I.    ./fortran -I../f90 -g -O2 -o .libs/nf_test test_get.o test_put.o
> nf_error.o     nf_test.o test_read.o test_write.o util.o fortlib.o
> -L/home/skirby/NETCDF42-ANDROID/lib ../fortran/.libs/libnetcdff.so
> /home/skirby/NETCDF42-ANDROID/lib/libnetcdf.so -lm -Wl,-rpath
> -Wl,/home/skirby/NETCDF42-ANDROID/lib
> test_get.o: In function `test_nf_get_var1_int1_':
> /home/skirby/ANDROID-NETCDF-FORTRAN-COMPILE/netcdf-fortran-4.2/nf_test/test_get.F:125:
> undefined reference to `nf_get_var1_int1_'
> /home/skirby/ANDROID-NETCDF-FORTRAN-COMPILE/netcdf-fortran-4.2/nf_test/test_get.F:129:
> undefined reference to `nf_get_var1_int1_'
> /home/skirby/ANDROID-NETCDF-FORTRAN-COMPILE/netcdf-fortran-4.2/nf_test/test_get.F:134:
> undefined reference to `nf_get_var1_int1_'
> /home/skirby/ANDROID-NETCDF-FORTRAN-COMPILE/netcdf-fortran-4.2/nf_test/test_get.F:152:
> undefined reference to `nf_get_var1_int1_'
> test_get.o: In function `test_nf_get_var1_int2_':

I don't think using netCDF-C version 4.3.1.1 rather than 4.2 is going
to fix the problem you are seeing with undefined references.

It looks like you are cross-compiling and the gfortran you have
built for that purpose isn't working correctly as a loader in tests
run by the configure script.  As an example of this, the netCDF-Fortran
configure script tries to determine C types corresponding to various
Fortran types by compiling, linking, and running some programs at
configure time, resulting in these constants defined in a "confdefs.h"
file:

 #define NF_INT1_IS_C_SIGNED_CHAR 1
 #define NF_INT2_IS_C_SHORT 1
 #define NF_INT_IS_C_INT 1
 #define NF_REAL_IS_C_FLOAT 1
 #define NF_DOUBLEPRECISION_IS_C_DOUBLE 1

When you run configure, all those constants are left undefined in
confdefs.h.  The reason they are not defined is due to failures such
as this, from the config.log you sent (absolute paths elided or
simplified for clarity):

    configure: checking if Fortran "byte" is C "signed char"
    configure: gcc -c -I${NCDIR}/include -g -O2 conftest.c
    conftest.c: In function 'sub_':
    conftest.c:4:3: warning: incompatible implicit declaration of built-in 
function 'exit' [enabled by default]
       exit(values[1] != -2 || values[2] != -3);
       ^
    configure: $? = 0
    configure: gfortran -g -O2 -c conftestf.f
    configure: $? = 0
    configure: gfortran -o conftest -g -O2 -L${NCDIR}/lib conftestf.o 
conftest.o  -lnetcdf
    configure: $? = 0
    configure: ./conftest
    ./configure: line 17846: ./conftest: cannot execute binary file
    configure: $? = 126
    configure: result: no

When I run configure for netCDF Fortran 4.2 using an installed netCDF C
4.3.1.1, the config.log output from this test is:

    configure: checking if Fortran "byte" is C "signed char"
    configure: gcc -c -I${NCDIR}/include -g -O2 conftest.c
    conftest.c: In function 'sub_':
    conftest.c:4:3: warning: incompatible implicit declaration of built-in 
function 'exit'
    configure: $? = 0
    configure: gfortran -g -O2 -c conftestf.f
    configure: $? = 0
    configure: gfortran -o conftest -g -O2 -L${NCDIR}/lib conftestf.o 
conftest.o  -lnetcdf
    configure: $? = 0
    configure: ./conftest
    configure: $? = 0
    configure: result: yes

The compiler warning is irrelevant, the important failure is "cannot
execute binary file", from which an error status 126 is returned on
your system.  Maybe your gfortran used as a cross-compiler is not
linking correctly on the 32-bit arm-linux platform that's your target,
or maybe our configure script is not working correctly for
cross-compiling, which we don't test.  This may be difficult to fix ...

--Russ

> 
> etc.
> 
> I have not built the netCDF C 4.3.1.1 code yet. These results are still
> based on netCDF C 4.2.
> 
> I set these environment variables:
> CPPFLAGS=-I/home/skirby/NETCDF42-ANDROID/include
> LDFLAGS=-L/home/skirby/NETCDF42-ANDROID/lib
> LIBS=-lnetcdf
> LD_LIBRARY_PATH=/home/skirby/NETCDF42-ANDROID/lib
> 
> 
> --Steve
> 
> 
> 
> 
> 
> 
> address@hidden> wrote:
> 
> > Hi Steve,
> >
> > Rather than using compiler flags related to underscores, I recommend
> > following the steps here, which work with many compiler combinations
> > without messing with underscores in function names:
> >
> >   http://www.unidata.ucar.edu/netcdf/docs/netcdf-fortran-install.html
> >
> > The instructions above explain when LD_LIBRARY_PATH may be required in
> > addition to LD_FLAGS and CPPFLAGS settings.  If this doesn't work for
> > you, we might be able to provide more help if you send the config.log
> > file generated by the configure script when you start building the
> > netCDF Fortran API from source.
> >
> > Also, it would be better to use the most recent netCDF C release, version
> > 4.3.1.1, with netCDF Fortran 4.2.  It has various bug fixes and
> > other improvements since netCDF C 4.2 was released, and it's compatible
> > with netCDF-Fortran version 4.2.
> >
> > --Russ
> >
> > > I have successfully cross-compiled netcdf C 4.2, i.e., build it on a
> > x86_64
> > > linux box to run on a android ARM.
> > >
> > > Now I'm trying to cross-compile netcdf fortran 4.2.  But I'm getting
> > > undefined references like the one I show below, when I run "gmake check".
> > >
> > >
> > > libtool: link: /home/me/ANDROID19/bin/arm-linux-androideabi-gfortran -l
> > > ./fortran -I../f90 -g -O2 -o .libs/nf_test test_get.o test_put.o
> > > nf_error.o     nf_test.o test_read.o test_write.o util.o fortlib.o
> > > ../fortran/.libs/libnetcdff.so -Wl,-rpath
> > -Wl,/home/me/NETCDF42-ANDROID/lib
> > > test_get.o: In function `test_nf_get_var1_int1_':
> > >
> > /home/me/ANDROID-NETCDF-FORTRAN-COMPILE/netcdf-fortran-4.2/nf_test/test_get.F:125:
> > > undefined reference to `nf_get_var1_int1_'
> > >
> > > and lots more very similar to this.
> > >
> > > Prior to this I compiled the netCDF C code, version 4.2.  Then I point
> > > CPPFLAGS=-I/path/to/netCDF-C-compile/include and
> > > LD_LIBRARY_PATH=/path/to/netCDF-C-compile/lib.
> > >
> > > If anybody could point me toward how to fix this or give me some ideas
> > that
> > > would be great.  If it helps at all, I have attached the config log file.
> > >
> > > TIA,
> > > SK
> > >
> > >
> >
> > Russ Rew                                         UCAR Unidata Program
> > address@hidden                      http://www.unidata.ucar.edu
> >
> >
> >
> > Ticket Details
> > ===================
> > Ticket ID: UAT-411621
> > Department: Support netCDF
> > Priority: Normal
> > Status: Closed
> >
> >
> 
> 

Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: UAT-411621
Department: Support netCDF
Priority: Normal
Status: Closed